class BIT:
    def __init__(self, n):
        self.node = [ 0 for _ in range(n+1) ]

    def add(self, idx, w):
        i = idx
        while i < len(self.node) - 1:
            self.node[i] += w
            i |= (i + 1)

    def sum_(self, idx):
        ret, i = 0, idx-1
        while i >= 0:
            ret += self.node[i]
            i = (i & (i + 1)) - 1
        return ret

    def sum(self, l, r):
        return self.sum_(r) - self.sum_(l)


n = int(input())
s = list(input())
q = int(input())

tree = [ BIT(n) for _ in range(26) ]
for i in range(n):
    tree_id = ord(s[i]) - ord("a")
    tree[tree_id].add(i, 1)

for _ in range(q):
    query = input().split()
    com = int(query[0])
    if com == 1:
        idx, new_char = int(query[1]), query[2]
        idx -= 1
        old_char = s[idx]
        new_id = ord(new_char) - ord("a")
        old_id = ord(old_char) - ord("a")

        tree[old_id].add(idx, -1)
        tree[new_id].add(idx, 1)
        s[idx] = new_char

    if com == 2:
        l, r = int(query[1]), int(query[2])
        ret = 0
        for c in range(26):
            if tree[c].sum(l-1, r) > 0:
                ret += 1
        print(ret) class BIT:
    def __init__(self, n):
        self.node = [ 0 for _ in range(n+1) ]

    def add(self, idx, w):
        i = idx
        while i < len(self.node) - 1:
            self.node[i] += w
            i |= (i + 1)

    def sum_(self, idx):
        ret, i = 0, idx-1
        while i >= 0:
            ret += self.node[i]
            i = (i & (i + 1)) - 1
        return ret

    def sum(self, l, r):
        return self.sum_(r) - self.sum_(l) BIT def __init__(self, n):
        self.node = [ 0 for _ in range(n+1) ]

     __init__ 0 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) 0 self.node = [ 0 for _ in range(n+1) ] self.node self node [ 0 for _ in range(n+1) ] self self n n def add(self, idx, w):
        i = idx
        while i < len(self.node) - 1:
            self.node[i] += w
            i |= (i + 1)

     add i = idx i idx while i < len(self.node) - 1:
            self.node[i] += w
            i |= (i + 1)

     i < len(self.node) - 1 i len(self.node) - 1 len(self.node) len self.node self node 1 self.node[i] += w self.node[i] self.node self node i w i |= (i + 1) i i + 1 i 1 self self idx idx w w def sum_(self, idx):
        ret, i = 0, idx-1
        while i >= 0:
            ret += self.node[i]
            i = (i & (i + 1)) - 1
        return ret

     sum_ ret, i = 0, idx-1 ret 0 i idx-1 idx 1 while i >= 0:
            ret += self.node[i]
            i = (i & (i + 1)) - 1
         i >= 0 i 0 ret += self.node[i] ret self.node[i] self.node self node i i = (i & (i + 1)) - 1 i (i & (i + 1)) - 1 i & (i + 1) i i + 1 i 1 1 return ret ret self self idx idx def sum(self, l, r):
        return self.sum_(r) - self.sum_(l) sum return self.sum_(r) - self.sum_(l) self.sum_(r) - self.sum_(l) self.sum_(r) self.sum_ self sum_ r self.sum_(l) self.sum_ self sum_ l self self l l r r n = int(input()) n int(input()) int input() input s = list(input()) s list(input()) list input() input q = int(input()) q int(input()) int input() input BIT(n) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BIT(n) BIT n tree = [ BIT(n) for _ in range(26) ] tree [ BIT(n) for _ in range(26) ] for i in range(n):
    tree_id = ord(s[i]) - ord("a")
    tree[tree_id].add(i, 1) i range(n) range n tree_id = ord(s[i]) - ord("a") tree_id ord(s[i]) - ord("a") ord(s[i]) ord s[i] s i ord("a") ord "a" tree[tree_id].add(i, 1) [tree_id].add [tree_id] tree tree_id add i 1 for _ in range(q):
    query = input().split()
    com = int(query[0])
    if com == 1:
        idx, new_char = int(query[1]), query[2]
        idx -= 1
        old_char = s[idx]
        new_id = ord(new_char) - ord("a")
        old_id = ord(old_char) - ord("a")

        tree[old_id].add(idx, -1)
        tree[new_id].add(idx, 1)
        s[idx] = new_char

    if com == 2:
        l, r = int(query[1]), int(query[2])
        ret = 0
        for c in range(26):
            if tree[c].sum(l-1, r) > 0:
                ret += 1
        print(ret) _ range(q) range q query = input().split() query input().split() ().split () input split com = int(query[0]) com int(query[0]) int query[0] query 0 if com == 1:
        idx, new_char = int(query[1]), query[2]
        idx -= 1
        old_char = s[idx]
        new_id = ord(new_char) - ord("a")
        old_id = ord(old_char) - ord("a")

        tree[old_id].add(idx, -1)
        tree[new_id].add(idx, 1)
        s[idx] = new_char

     com == 1 com 1 idx, new_char = int(query[1]), query[2] idx int(query[1]) int query[1] query 1 new_char query[2] query 2 idx -= 1 idx 1 old_char = s[idx] old_char s[idx] s idx new_id = ord(new_char) - ord("a") new_id ord(new_char) - ord("a") ord(new_char) ord new_char ord("a") ord "a" old_id = ord(old_char) - ord("a") old_id ord(old_char) - ord("a") ord(old_char) ord old_char ord("a") ord "a" tree[old_id].add(idx, -1) [old_id].add [old_id] tree old_id add idx -1 tree[new_id].add(idx, 1) [new_id].add [new_id] tree new_id add idx 1 s[idx] = new_char s[idx] s idx new_char if com == 2:
        l, r = int(query[1]), int(query[2])
        ret = 0
        for c in range(26):
            if tree[c].sum(l-1, r) > 0:
                ret += 1
        print(ret) com == 2 com 2 l, r = int(query[1]), int(query[2]) l int(query[1]) int query[1] query 1 r int(query[2]) int query[2] query 2 ret = 0 ret 0 for c in range(26):
            if tree[c].sum(l-1, r) > 0:
                ret += 1
         c range(26) range 26 if tree[c].sum(l-1, r) > 0:
                ret += 1
         tree[c].sum(l-1, r) > 0 tree[c].sum(l-1, r) [c].sum [c] tree c sum l-1 l 1 r 0 ret += 1 ret 1 print(ret) print ret ret = 0 0 ret tree = [ BIT(n) for _ in range(26) ] [ BIT(n) for _ in range(26) ] tree idx, new_char = int(query[1]), query[2] int(query[1]) idx com = int(query[0]) int(query[0]) com tree_id = ord(s[i]) - ord("a") ord(s[i]) - ord("a") tree_id query = input().split() input().split() query r = int(query[1]), int(query[2]) int(query[2]) r new_char = int(query[1]), query[2] query[2] new_char idx -= 1 1 idx n = int(input()) int(input()) n s = list(input()) list(input()) s ret += 1 1 ret old_char = s[idx] s[idx] old_char q = int(input()) int(input()) q old_id = ord(old_char) - ord("a") ord(old_char) - ord("a") old_id class BIT:
    def __init__(self, n):
        self.node = [ 0 for _ in range(n+1) ]

    def add(self, idx, w):
        i = idx
        while i < len(self.node) - 1:
            self.node[i] += w
            i |= (i + 1)

    def sum_(self, idx):
        ret, i = 0, idx-1
        while i >= 0:
            ret += self.node[i]
            i = (i & (i + 1)) - 1
        return ret

    def sum(self, l, r):
        return self.sum_(r) - self.sum_(l) class BIT:
    def __init__(self, n):
        self.node = [ 0 for _ in range(n+1) ]

    def add(self, idx, w):
        i = idx
        while i < len(self.node) - 1:
            self.node[i] += w
            i |= (i + 1)

    def sum_(self, idx):
        ret, i = 0, idx-1
        while i >= 0:
            ret += self.node[i]
            i = (i & (i + 1)) - 1
        return ret

    def sum(self, l, r):
        return self.sum_(r) - self.sum_(l) BIT l, r = int(query[1]), int(query[2]) int(query[1]) l new_id = ord(new_char) - ord("a") ord(new_char) - ord("a") new_id
class BIT:
    def __init__(self, n):
        self.node = [ 0 for _ in range(n+1) ]

    def add(self, idx, w):
        i = idx
        while i < len(self.node) - 1:
            self.node[i] += w
            i |= (i + 1)

    def sum_(self, idx):
        ret, i = 0, idx-1
        while i >= 0:
            ret += self.node[i]
            i = (i & (i + 1)) - 1
        return ret

    def sum(self, l, r):
        return self.sum_(r) - self.sum_(l)


n = int(input())
s = list(input())
q = int(input())

tree = [ BIT(n) for _ in range(26) ]
for i in range(n):
    tree_id = ord(s[i]) - ord("a")
    tree[tree_id].add(i, 1)

for _ in range(q):
    query = input().split()
    com = int(query[0])
    if com == 1:
        idx, new_char = int(query[1]), query[2]
        idx -= 1
        old_char = s[idx]
        new_id = ord(new_char) - ord("a")
        old_id = ord(old_char) - ord("a")

        tree[old_id].add(idx, -1)
        tree[new_id].add(idx, 1)
        s[idx] = new_char

    if com == 2:
        l, r = int(query[1]), int(query[2])
        ret = 0
        for c in range(26):
            if tree[c].sum(l-1, r) > 0:
                ret += 1
        print(ret)