#!/usr/bin/env python3

class Bit:
    # Binary Indexed Tree
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i + 1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key])

(n,), (s,), _, *q = map(str.split, open(0))
*s, = s
BIT = [Bit(int(n)) for _ in [0] * 26]
for e, t in enumerate(s):
    BIT[ord(t) - 97].add(e, 1)
for a, b, c in q:
    if a == "1":
        i = int(b)
        BIT[ord(s[i - 1]) - 97].add(i - 1, -1)
        s[i - 1] = c
        BIT[ord(c) - 97].add(i - 1, 1)
    else:
        l, r = int(b), int(c)
        print(sum(BIT[i].sum(r) - BIT[i].sum(l - 1) > 0 for i in range(26))) class Bit:
    # Binary Indexed Tree
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i + 1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key]) Bit def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

     __init__ self.size = n self.size self size n self.tree = [0] * (n + 1) self.tree self tree [0] * (n + 1) [0] 0 n + 1 n 1 self self n n def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i + 1)
            yield csum - psum
            psum = csum
        raise StopIteration()

     __iter__ psum = 0 psum 0 for i in range(self.size):
            csum = self.sum(i + 1)
            yield csum - psum
            psum = csum
         i range(self.size) range self.size self size csum = self.sum(i + 1) csum self.sum(i + 1) self.sum self sum i + 1 i 1 yield csum - psum csum - psum csum psum psum = csum psum csum raise StopIteration() StopIteration() StopIteration self self def __str__(self):  # O(nlogn)
        return str(list(self))

     __str__ return str(list(self)) str(list(self)) str list(self) list self self self def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

     sum if not (0 <= i <= self.size): raise ValueError("error!")
         not (0 <= i <= self.size) 0 <= i <= self.size 0 <= i 0 i self.size self size s = 0 s 0 while i>0:
            s += self.tree[i]
            i -= i & -i
         i>0 i 0 s += self.tree[i] s self.tree[i] self.tree self tree i i -= i & -i i i & -i i -i i return s s self self i i def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

     add if not (0 <= i < self.size): raise ValueError("error!")
         not (0 <= i < self.size) 0 <= i < self.size 0 <= i 0 i self.size self size i += 1 i 1 while i <= self.size:
            self.tree[i] += x
            i += i & -i

     i <= self.size i self.size self size self.tree[i] += x self.tree[i] self.tree self tree i x i += i & -i i i & -i i -i i self self i i x x def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

     __getitem__ if not (0 <= key < self.size): raise IndexError("error!")
         not (0 <= key < self.size) 0 <= key < self.size 0 <= key 0 key self.size self size return self.sum(key+1) - self.sum(key) self.sum(key+1) - self.sum(key) self.sum(key+1) self.sum self sum key+1 key 1 self.sum(key) self.sum self sum key self self key key def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key]) __setitem__ if not (0 <= key < self.size): raise IndexError("error!")
         not (0 <= key < self.size) 0 <= key < self.size 0 <= key 0 key self.size self size self.add(key, value - self[key]) self.add self add key value - self[key] value self[key] self key self self key key value value (n,), (s,), _, *q = map(str.split, open(0)) n map(str.split, open(0)) map str.split str split open(0) open 0 s _ *q q *s, = s *s s s Bit(int(n)) for _ in [0] * 26 for _ in [0] * 26 _ [0] * 26 [0] 0 26 for _ in [0] * 26 Bit(int(n)) Bit int(n) int n BIT = [Bit(int(n)) for _ in [0] * 26] BIT [Bit(int(n)) for _ in [0] * 26] for e, t in enumerate(s):
    BIT[ord(t) - 97].add(e, 1) e t enumerate(s) enumerate s BIT[ord(t) - 97].add(e, 1) [ord(t) - 97].add [ord(t) - 97] BIT ord(t) - 97 ord(t) ord t 97 add e 1 for a, b, c in q:
    if a == "1":
        i = int(b)
        BIT[ord(s[i - 1]) - 97].add(i - 1, -1)
        s[i - 1] = c
        BIT[ord(c) - 97].add(i - 1, 1)
    else:
        l, r = int(b), int(c)
        print(sum(BIT[i].sum(r) - BIT[i].sum(l - 1) > 0 for i in range(26))) a b c q if a == "1":
        i = int(b)
        BIT[ord(s[i - 1]) - 97].add(i - 1, -1)
        s[i - 1] = c
        BIT[ord(c) - 97].add(i - 1, 1)
    else:
        l, r = int(b), int(c)
        print(sum(BIT[i].sum(r) - BIT[i].sum(l - 1) > 0 for i in range(26))) a == "1" a "1" i = int(b) i int(b) int b BIT[ord(s[i - 1]) - 97].add(i - 1, -1) [ord(s[i - 1]) - 97].add [ord(s[i - 1]) - 97] BIT ord(s[i - 1]) - 97 ord(s[i - 1]) ord s[i - 1] s i - 1 i 1 97 add i - 1 i 1 -1 s[i - 1] = c s[i - 1] s i - 1 i 1 c BIT[ord(c) - 97].add(i - 1, 1) [ord(c) - 97].add [ord(c) - 97] BIT ord(c) - 97 ord(c) ord c 97 add i - 1 i 1 1 l, r = int(b), int(c) l int(b) int b r int(c) int c print(sum(BIT[i].sum(r) - BIT[i].sum(l - 1) > 0 for i in range(26))) print sum(BIT[i].sum(r) - BIT[i].sum(l - 1) > 0 for i in range(26)) sum BIT[i].sum(r) - BIT[i].sum(l - 1) > 0 BIT[i].sum(r) - BIT[i].sum(l - 1) BIT[i].sum(r) [i].sum [i] BIT i sum r BIT[i].sum(l - 1) [i].sum [i] BIT i sum l - 1 l 1 0 s,), _, *q = map(str.split, open(0)) map(str.split, open(0)) s l, r = int(b), int(c) int(b) l i = int(b) int(b) i r = int(b), int(c) int(c) r _, *q = map(str.split, open(0)) map(str.split, open(0)) _ class Bit:
    # Binary Indexed Tree
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i + 1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key]) class Bit:
    # Binary Indexed Tree
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i + 1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key]) Bit n,), (s,), _, *q = map(str.split, open(0)) map(str.split, open(0)) n BIT = [Bit(int(n)) for _ in [0] * 26] [Bit(int(n)) for _ in [0] * 26] BIT
#!/usr/bin/env python3

class Bit:
    # Binary Indexed Tree
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i + 1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key])

(n,), (s,), _, *q = map(str.split, open(0))
*s, = s
BIT = [Bit(int(n)) for _ in [0] * 26]
for e, t in enumerate(s):
    BIT[ord(t) - 97].add(e, 1)
for a, b, c in q:
    if a == "1":
        i = int(b)
        BIT[ord(s[i - 1]) - 97].add(i - 1, -1)
        s[i - 1] = c
        BIT[ord(c) - 97].add(i - 1, 1)
    else:
        l, r = int(b), int(c)
        print(sum(BIT[i].sum(r) - BIT[i].sum(l - 1) > 0 for i in range(26)))
