def segfunc(x,y):
  return x|y

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)


N = int(input())
S = str(input());Q = int(input())
A = []
for i in range(N):
  temp = S[i]
  num = ord(temp) - 97
  A.append(pow(2,num))
Tree = SegmentTree(A, segfunc, 0)
for i in range(Q):
  query = list(map(str,input().split()))
  if query[0] == "1":
    loc = int(query[1])-1 #0index
    num = ord(query[2])-97
    Tree.update(loc,pow(2,num))
  else:
    left = int(query[1])-1
    right = int(query[2])-1
    ret = Tree.sum(left,right+1)
    ans = 0
    for j in range(26):
      if (ret>>j)&1 == 1:
        ans += 1
    print(ans) def segfunc(x,y):
  return x|y segfunc return x|y x|y x y x x y y class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val) SegmentTree def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

     __init__ n = 1 << (len(A) - 1).bit_length() n 1 << (len(A) - 1).bit_length() 1 (len(A) - 1).bit_length() len(A) - 1).bit_length len(A) - 1 len(A) len A 1 bit_length tree = [unit] * (2 * n) tree [unit] * (2 * n) [unit] unit 2 * n 2 n for i, v in enumerate(A):
            tree[i + n] = v
         i v enumerate(A) enumerate A tree[i + n] = v tree[i + n] tree i + n i n v for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
         i range(n - 1, 0, -1) range n - 1 n 1 0 -1 tree[i] = dot(tree[i << 1], tree[i << 1 | 1]) tree[i] tree i dot(tree[i << 1], tree[i << 1 | 1]) dot tree[i << 1] tree i << 1 i 1 tree[i << 1 | 1] tree i << 1 | 1 i << 1 i 1 1 self._n = n self._n self _n n self._tree = tree self._tree self _tree tree self._dot = dot self._dot self _dot dot self._unit = unit self._unit self _unit unit self self A A dot dot unit unit def __getitem__(self, i):
        return self._tree[i + self._n]

     __getitem__ return self._tree[i + self._n] self._tree[i + self._n] self._tree self _tree i + self._n i self._n self _n self self i i def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

     update i += self._n i self._n self _n self._tree[i] = v self._tree[i] self._tree self _tree i v while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

     i != 1 i 1 i >>= 1 i 1 self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1]) self._tree[i] self._tree self _tree i self._dot(self._tree[i << 1], self._tree[i << 1 | 1]) self._dot self _dot self._tree[i << 1] self._tree self _tree i << 1 i 1 self._tree[i << 1 | 1] self._tree self _tree i << 1 | 1 i << 1 i 1 1 self self i i v v def add(self, i, v):
        self.update(i, self[i] + v)

     add self.update(i, self[i] + v) self.update self update i self[i] + v self[i] self i v self self i i v v def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val) sum l += self._n l self._n self _n r += self._n r self._n self _n l_val = r_val = self._unit l_val self._unit self _unit = r_val = self._unit r_val self._unit while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
         l < r l r if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
             l & 1 l 1 l_val = self._dot(l_val, self._tree[l]) l_val self._dot(l_val, self._tree[l]) self._dot self _dot l_val self._tree[l] self._tree self _tree l l += 1 l 1 if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
             r & 1 r 1 r -= 1 r 1 r_val = self._dot(self._tree[r], r_val) r_val self._dot(self._tree[r], r_val) self._dot self _dot self._tree[r] self._tree self _tree r r_val l >>= 1 l 1 r >>= 1 r 1 return self._dot(l_val, r_val) self._dot(l_val, r_val) self._dot self _dot l_val r_val self self l l r r object N = int(input()) N int(input()) int input() input S = str(input()) S str(input()) str input() input Q = int(input()) Q int(input()) int input() input A = [] A [] for i in range(N):
  temp = S[i]
  num = ord(temp) - 97
  A.append(pow(2,num)) i range(N) range N temp = S[i] temp S[i] S i num = ord(temp) - 97 num ord(temp) - 97 ord(temp) ord temp 97 A.append(pow(2,num)) A.append A append pow(2,num) pow 2 num Tree = SegmentTree(A, segfunc, 0) Tree SegmentTree(A, segfunc, 0) SegmentTree A segfunc 0 for i in range(Q):
  query = list(map(str,input().split()))
  if query[0] == "1":
    loc = int(query[1])-1 #0index
    num = ord(query[2])-97
    Tree.update(loc,pow(2,num))
  else:
    left = int(query[1])-1
    right = int(query[2])-1
    ret = Tree.sum(left,right+1)
    ans = 0
    for j in range(26):
      if (ret>>j)&1 == 1:
        ans += 1
    print(ans) i range(Q) range Q query = list(map(str,input().split())) query list(map(str,input().split())) list map(str,input().split()) map str input().split() ().split () input split if query[0] == "1":
    loc = int(query[1])-1 #0index
    num = ord(query[2])-97
    Tree.update(loc,pow(2,num))
  else:
    left = int(query[1])-1
    right = int(query[2])-1
    ret = Tree.sum(left,right+1)
    ans = 0
    for j in range(26):
      if (ret>>j)&1 == 1:
        ans += 1
    print(ans) query[0] == "1" query[0] query 0 "1" loc = int(query[1])-1 loc int(query[1])-1 int(query[1]) int query[1] query 1 1 num = ord(query[2])-97 num ord(query[2])-97 ord(query[2]) ord query[2] query 2 97 Tree.update(loc,pow(2,num)) Tree.update Tree update loc pow(2,num) pow 2 num left = int(query[1])-1 left int(query[1])-1 int(query[1]) int query[1] query 1 1 right = int(query[2])-1 right int(query[2])-1 int(query[2]) int query[2] query 2 1 ret = Tree.sum(left,right+1) ret Tree.sum(left,right+1) Tree.sum Tree sum left right+1 right 1 ans = 0 ans 0 for j in range(26):
      if (ret>>j)&1 == 1:
        ans += 1
     j range(26) range 26 if (ret>>j)&1 == 1:
        ans += 1
     (ret>>j)&1 == 1 (ret>>j)&1 ret>>j ret j 1 1 ans += 1 ans 1 print(ans) print ans ans += 1 1 ans ans = 0 0 ans def segfunc(x,y):
  return x|y def segfunc(x,y):
  return x|y segfunc temp = S[i] S[i] temp Q = int(input()) int(input()) Q num = ord(temp) - 97 ord(temp) - 97 num left = int(query[1])-1 int(query[1])-1 left S = str(input()) str(input()) S loc = int(query[1])-1 int(query[1])-1 loc A = [] [] A right = int(query[2])-1 int(query[2])-1 right N = int(input()) int(input()) N ret = Tree.sum(left,right+1) Tree.sum(left,right+1) ret class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val) class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val) SegmentTree Tree = SegmentTree(A, segfunc, 0) SegmentTree(A, segfunc, 0) Tree query = list(map(str,input().split())) list(map(str,input().split())) query num = ord(query[2])-97 ord(query[2])-97 num
def segfunc(x,y):
  return x|y

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)


N = int(input())
S = str(input());Q = int(input())
A = []
for i in range(N):
  temp = S[i]
  num = ord(temp) - 97
  A.append(pow(2,num))
Tree = SegmentTree(A, segfunc, 0)
for i in range(Q):
  query = list(map(str,input().split()))
  if query[0] == "1":
    loc = int(query[1])-1 #0index
    num = ord(query[2])-97
    Tree.update(loc,pow(2,num))
  else:
    left = int(query[1])-1
    right = int(query[2])-1
    ret = Tree.sum(left,right+1)
    ans = 0
    for j in range(26):
      if (ret>>j)&1 == 1:
        ans += 1
    print(ans)
