import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()

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 += 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)

def resolve():
    n = int(input())
    trees = [[0] * n for _ in range(26)]
    character = [None] * n

    for i, c in enumerate(input()):
        c = ord(c) - ord('a')
        character[i] = c
        trees[c][i] = 1
    for i in range(26):
        trees[i] = SegmentTree(trees[i], max, 0)

    for _ in range(int(input())):
        q, *A = input().split()
        if q == '1':
            i, c = A
            i = int(i) - 1
            c = ord(c) - ord('a')
            trees[character[i]].update(i, 0)
            character[i] = c
            trees[c].update(i, 1)
        else:
            l, r = map(int, A)
            l -= 1
            print(sum(trees[i].sum(l, r) for i in range(26)))
resolve() import sys sys sys.setrecursionlimit(2147483647) sys.setrecursionlimit sys setrecursionlimit 2147483647 INF = 1 << 60 INF 1 << 60 1 60 MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 input = lambda:sys.stdin.readline().rstrip() input lambda:sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip 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 += 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 += 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 def resolve():
    n = int(input())
    trees = [[0] * n for _ in range(26)]
    character = [None] * n

    for i, c in enumerate(input()):
        c = ord(c) - ord('a')
        character[i] = c
        trees[c][i] = 1
    for i in range(26):
        trees[i] = SegmentTree(trees[i], max, 0)

    for _ in range(int(input())):
        q, *A = input().split()
        if q == '1':
            i, c = A
            i = int(i) - 1
            c = ord(c) - ord('a')
            trees[character[i]].update(i, 0)
            character[i] = c
            trees[c].update(i, 1)
        else:
            l, r = map(int, A)
            l -= 1
            print(sum(trees[i].sum(l, r) for i in range(26))) resolve n = int(input()) n int(input()) int input() input [0] * n for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [0] * n [0] 0 n trees = [[0] * n for _ in range(26)] trees [[0] * n for _ in range(26)] character = [None] * n character [None] * n [None] None n for i, c in enumerate(input()):
        c = ord(c) - ord('a')
        character[i] = c
        trees[c][i] = 1
     i c enumerate(input()) enumerate input() input c = ord(c) - ord('a') c ord(c) - ord('a') ord(c) ord c ord('a') ord 'a' character[i] = c character[i] character i c trees[c][i] = 1 trees[c][i] [c] trees c i 1 for i in range(26):
        trees[i] = SegmentTree(trees[i], max, 0)

     i range(26) range 26 trees[i] = SegmentTree(trees[i], max, 0) trees[i] trees i SegmentTree(trees[i], max, 0) SegmentTree trees[i] trees i max 0 for _ in range(int(input())):
        q, *A = input().split()
        if q == '1':
            i, c = A
            i = int(i) - 1
            c = ord(c) - ord('a')
            trees[character[i]].update(i, 0)
            character[i] = c
            trees[c].update(i, 1)
        else:
            l, r = map(int, A)
            l -= 1
            print(sum(trees[i].sum(l, r) for i in range(26))) _ range(int(input())) range int(input()) int input() input q, *A = input().split() q input().split() ().split () input split *A A if q == '1':
            i, c = A
            i = int(i) - 1
            c = ord(c) - ord('a')
            trees[character[i]].update(i, 0)
            character[i] = c
            trees[c].update(i, 1)
        else:
            l, r = map(int, A)
            l -= 1
            print(sum(trees[i].sum(l, r) for i in range(26))) q == '1' q '1' i, c = A i A c i = int(i) - 1 i int(i) - 1 int(i) int i 1 c = ord(c) - ord('a') c ord(c) - ord('a') ord(c) ord c ord('a') ord 'a' trees[character[i]].update(i, 0) [character[i]].update [character[i]] trees character[i] character i update i 0 character[i] = c character[i] character i c trees[c].update(i, 1) [c].update [c] trees c update i 1 l, r = map(int, A) l map(int, A) map int A r l -= 1 l 1 print(sum(trees[i].sum(l, r) for i in range(26))) print sum(trees[i].sum(l, r) for i in range(26)) sum trees[i].sum(l, r) [i].sum [i] trees i sum l r resolve() resolve INF = 1 << 60 1 << 60 INF MOD = 10**9 + 7 10**9 + 7 MOD 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 += 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 += 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 input = lambda:sys.stdin.readline().rstrip() lambda:sys.stdin.readline().rstrip() input def resolve():
    n = int(input())
    trees = [[0] * n for _ in range(26)]
    character = [None] * n

    for i, c in enumerate(input()):
        c = ord(c) - ord('a')
        character[i] = c
        trees[c][i] = 1
    for i in range(26):
        trees[i] = SegmentTree(trees[i], max, 0)

    for _ in range(int(input())):
        q, *A = input().split()
        if q == '1':
            i, c = A
            i = int(i) - 1
            c = ord(c) - ord('a')
            trees[character[i]].update(i, 0)
            character[i] = c
            trees[c].update(i, 1)
        else:
            l, r = map(int, A)
            l -= 1
            print(sum(trees[i].sum(l, r) for i in range(26))) def resolve():
    n = int(input())
    trees = [[0] * n for _ in range(26)]
    character = [None] * n

    for i, c in enumerate(input()):
        c = ord(c) - ord('a')
        character[i] = c
        trees[c][i] = 1
    for i in range(26):
        trees[i] = SegmentTree(trees[i], max, 0)

    for _ in range(int(input())):
        q, *A = input().split()
        if q == '1':
            i, c = A
            i = int(i) - 1
            c = ord(c) - ord('a')
            trees[character[i]].update(i, 0)
            character[i] = c
            trees[c].update(i, 1)
        else:
            l, r = map(int, A)
            l -= 1
            print(sum(trees[i].sum(l, r) for i in range(26))) resolve
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()

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 += 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)

def resolve():
    n = int(input())
    trees = [[0] * n for _ in range(26)]
    character = [None] * n

    for i, c in enumerate(input()):
        c = ord(c) - ord('a')
        character[i] = c
        trees[c][i] = 1
    for i in range(26):
        trees[i] = SegmentTree(trees[i], max, 0)

    for _ in range(int(input())):
        q, *A = input().split()
        if q == '1':
            i, c = A
            i = int(i) - 1
            c = ord(c) - ord('a')
            trees[character[i]].update(i, 0)
            character[i] = c
            trees[c].update(i, 1)
        else:
            l, r = map(int, A)
            l -= 1
            print(sum(trees[i].sum(l, r) for i in range(26)))
resolve()