import sys

input = lambda: sys.stdin.readline().rstrip()


class SegTree:

    def __init__(self, init_val, segfunc, ide_ele):

        n = len(init_val)
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.num = 2**(n - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num

        for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]

        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])

    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k - 1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])

    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res


def solve():

    N = int(input())
    S = list(input())
    Q = int(input())
    seg = [[0 for _ in range(N)] for _ in range(26)]

    for i in range(N):
        al = ord(S[i]) - ord('a')
        seg[al][i] = 1

    segtree = []
    segfunc = lambda a, b: a | b

    for i in range(26):
        segtree.append(SegTree(seg[i], segfunc, 0))

    ans = []
    for i in range(Q):
        a, b, c = input().split()
        a = int(a)

        if a == 1:
            b = int(b) - 1
            ps = S[b]
            S[b] = c
            segtree[ord(ps) - ord('a')].update(b, 0)
            segtree[ord(c) - ord('a')].update(b, 1)
        elif a == 2:
            b, c = int(b) - 1, int(c)
            count = 0
            for i in range(26):
                count += segtree[i].query(b, c)
            ans.append(count)

    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    solve() import sys sys 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 SegTree:

    def __init__(self, init_val, segfunc, ide_ele):

        n = len(init_val)
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.num = 2**(n - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num

        for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]

        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])

    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k - 1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])

    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res SegTree def __init__(self, init_val, segfunc, ide_ele):

        n = len(init_val)
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.num = 2**(n - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num

        for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]

        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])

     __init__ n = len(init_val) n len(init_val) len init_val self.ide_ele = ide_ele self.ide_ele self ide_ele ide_ele self.segfunc = segfunc self.segfunc self segfunc segfunc self.num = 2**(n - 1).bit_length() self.num self num 2**(n - 1).bit_length() 2 (n - 1).bit_length() n - 1).bit_length n - 1 n 1 bit_length self.seg = [self.ide_ele] * 2 * self.num self.seg self seg [self.ide_ele] * 2 * self.num [self.ide_ele] * 2 [self.ide_ele] self.ide_ele self ide_ele 2 self.num self num for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]

         i range(n) range n self.seg[i + self.num - 1] = init_val[i] self.seg[i + self.num - 1] self.seg self seg i + self.num - 1 i + self.num i self.num self num 1 init_val[i] init_val i for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])

     i range(self.num - 2, -1, -1) range self.num - 2 self.num self num 2 -1 -1 self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) self.seg[i] self.seg self seg i self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) self.segfunc self segfunc self.seg[2 * i + 1] self.seg self seg 2 * i + 1 2 * i 2 i 1 self.seg[2 * i + 2] self.seg self seg 2 * i + 2 2 * i 2 i 2 self self init_val init_val segfunc segfunc ide_ele ide_ele def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k - 1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])

     update k += self.num - 1 k self.num - 1 self.num self num 1 self.seg[k] = x self.seg[k] self.seg self seg k x while k:
            k = (k - 1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])

     k k = (k - 1) // 2 k (k - 1) // 2 k - 1 k 1 2 self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) self.seg[k] self.seg self seg k self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) self.segfunc self segfunc self.seg[k * 2 + 1] self.seg self seg k * 2 + 1 k * 2 k 2 1 self.seg[k * 2 + 2] self.seg self seg k * 2 + 2 k * 2 k 2 2 self self k k x x def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res query if q <= p:
            return self.ide_ele
         q <= p q p return self.ide_ele self.ide_ele self ide_ele p += self.num - 1 p self.num - 1 self.num self num 1 q += self.num - 2 q self.num - 2 self.num self num 2 res = self.ide_ele res self.ide_ele self ide_ele while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
         q - p > 1 q - p q p 1 if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
             p & 1 == 0 p & 1 p 1 0 res = self.segfunc(res, self.seg[p]) res self.segfunc(res, self.seg[p]) self.segfunc self segfunc res self.seg[p] self.seg self seg p if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
             q & 1 == 1 q & 1 q 1 1 res = self.segfunc(res, self.seg[q]) res self.segfunc(res, self.seg[q]) self.segfunc self segfunc res self.seg[q] self.seg self seg q q -= 1 q 1 p = p // 2 p p // 2 p 2 q = (q - 1) // 2 q (q - 1) // 2 q - 1 q 1 2 if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
         p == q p q res = self.segfunc(res, self.seg[p]) res self.segfunc(res, self.seg[p]) self.segfunc self segfunc res self.seg[p] self.seg self seg p res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q]) res self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q]) self.segfunc self segfunc self.segfunc(res, self.seg[p]) self.segfunc self segfunc res self.seg[p] self.seg self seg p self.seg[q] self.seg self seg q return res res self self p p q q def solve():

    N = int(input())
    S = list(input())
    Q = int(input())
    seg = [[0 for _ in range(N)] for _ in range(26)]

    for i in range(N):
        al = ord(S[i]) - ord('a')
        seg[al][i] = 1

    segtree = []
    segfunc = lambda a, b: a | b

    for i in range(26):
        segtree.append(SegTree(seg[i], segfunc, 0))

    ans = []
    for i in range(Q):
        a, b, c = input().split()
        a = int(a)

        if a == 1:
            b = int(b) - 1
            ps = S[b]
            S[b] = c
            segtree[ord(ps) - ord('a')].update(b, 0)
            segtree[ord(c) - ord('a')].update(b, 1)
        elif a == 2:
            b, c = int(b) - 1, int(c)
            count = 0
            for i in range(26):
                count += segtree[i].query(b, c)
            ans.append(count)

    print('\n'.join(map(str, ans))) solve 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 [0 for _ in range(N)] for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [0 for _ in range(N)] seg = [[0 for _ in range(N)] for _ in range(26)] seg [[0 for _ in range(N)] for _ in range(26)] for i in range(N):
        al = ord(S[i]) - ord('a')
        seg[al][i] = 1

     i range(N) range N al = ord(S[i]) - ord('a') al ord(S[i]) - ord('a') ord(S[i]) ord S[i] S i ord('a') ord 'a' seg[al][i] = 1 seg[al][i] [al] seg al i 1 segtree = [] segtree [] segfunc = lambda a, b: a | b segfunc lambda a, b: a | b a | b a b a b for i in range(26):
        segtree.append(SegTree(seg[i], segfunc, 0))

     i range(26) range 26 segtree.append(SegTree(seg[i], segfunc, 0)) segtree.append segtree append SegTree(seg[i], segfunc, 0) SegTree seg[i] seg i segfunc 0 ans = [] ans [] for i in range(Q):
        a, b, c = input().split()
        a = int(a)

        if a == 1:
            b = int(b) - 1
            ps = S[b]
            S[b] = c
            segtree[ord(ps) - ord('a')].update(b, 0)
            segtree[ord(c) - ord('a')].update(b, 1)
        elif a == 2:
            b, c = int(b) - 1, int(c)
            count = 0
            for i in range(26):
                count += segtree[i].query(b, c)
            ans.append(count)

     i range(Q) range Q a, b, c = input().split() a input().split() ().split () input split b c a = int(a) a int(a) int a if a == 1:
            b = int(b) - 1
            ps = S[b]
            S[b] = c
            segtree[ord(ps) - ord('a')].update(b, 0)
            segtree[ord(c) - ord('a')].update(b, 1)
        elif a == 2:
            b, c = int(b) - 1, int(c)
            count = 0
            for i in range(26):
                count += segtree[i].query(b, c)
            ans.append(count)

     a == 1 a 1 b = int(b) - 1 b int(b) - 1 int(b) int b 1 ps = S[b] ps S[b] S b S[b] = c S[b] S b c segtree[ord(ps) - ord('a')].update(b, 0) [ord(ps) - ord('a')].update [ord(ps) - ord('a')] segtree ord(ps) - ord('a') ord(ps) ord ps ord('a') ord 'a' update b 0 segtree[ord(c) - ord('a')].update(b, 1) [ord(c) - ord('a')].update [ord(c) - ord('a')] segtree ord(c) - ord('a') ord(c) ord c ord('a') ord 'a' update b 1 elif a == 2:
            b, c = int(b) - 1, int(c)
            count = 0
            for i in range(26):
                count += segtree[i].query(b, c)
            ans.append(count)

     a == 2 a 2 b, c = int(b) - 1, int(c) b int(b) - 1 int(b) int b 1 c int(c) int c count = 0 count 0 for i in range(26):
                count += segtree[i].query(b, c)
             i range(26) range 26 count += segtree[i].query(b, c) count segtree[i].query(b, c) [i].query [i] segtree i query b c ans.append(count) ans.append ans append count print('\n'.join(map(str, ans))) print '\n'.join(map(str, ans)) '\n'.join '\n' join map(str, ans) map str ans if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input def solve():

    N = int(input())
    S = list(input())
    Q = int(input())
    seg = [[0 for _ in range(N)] for _ in range(26)]

    for i in range(N):
        al = ord(S[i]) - ord('a')
        seg[al][i] = 1

    segtree = []
    segfunc = lambda a, b: a | b

    for i in range(26):
        segtree.append(SegTree(seg[i], segfunc, 0))

    ans = []
    for i in range(Q):
        a, b, c = input().split()
        a = int(a)

        if a == 1:
            b = int(b) - 1
            ps = S[b]
            S[b] = c
            segtree[ord(ps) - ord('a')].update(b, 0)
            segtree[ord(c) - ord('a')].update(b, 1)
        elif a == 2:
            b, c = int(b) - 1, int(c)
            count = 0
            for i in range(26):
                count += segtree[i].query(b, c)
            ans.append(count)

    print('\n'.join(map(str, ans))) def solve():

    N = int(input())
    S = list(input())
    Q = int(input())
    seg = [[0 for _ in range(N)] for _ in range(26)]

    for i in range(N):
        al = ord(S[i]) - ord('a')
        seg[al][i] = 1

    segtree = []
    segfunc = lambda a, b: a | b

    for i in range(26):
        segtree.append(SegTree(seg[i], segfunc, 0))

    ans = []
    for i in range(Q):
        a, b, c = input().split()
        a = int(a)

        if a == 1:
            b = int(b) - 1
            ps = S[b]
            S[b] = c
            segtree[ord(ps) - ord('a')].update(b, 0)
            segtree[ord(c) - ord('a')].update(b, 1)
        elif a == 2:
            b, c = int(b) - 1, int(c)
            count = 0
            for i in range(26):
                count += segtree[i].query(b, c)
            ans.append(count)

    print('\n'.join(map(str, ans))) solve class SegTree:

    def __init__(self, init_val, segfunc, ide_ele):

        n = len(init_val)
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.num = 2**(n - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num

        for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]

        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])

    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k - 1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])

    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res class SegTree:

    def __init__(self, init_val, segfunc, ide_ele):

        n = len(init_val)
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.num = 2**(n - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num

        for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]

        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])

    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k - 1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])

    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res SegTree
import sys

input = lambda: sys.stdin.readline().rstrip()


class SegTree:

    def __init__(self, init_val, segfunc, ide_ele):

        n = len(init_val)
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.num = 2**(n - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num

        for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]

        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])

    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k - 1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])

    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res


def solve():

    N = int(input())
    S = list(input())
    Q = int(input())
    seg = [[0 for _ in range(N)] for _ in range(26)]

    for i in range(N):
        al = ord(S[i]) - ord('a')
        seg[al][i] = 1

    segtree = []
    segfunc = lambda a, b: a | b

    for i in range(26):
        segtree.append(SegTree(seg[i], segfunc, 0))

    ans = []
    for i in range(Q):
        a, b, c = input().split()
        a = int(a)

        if a == 1:
            b = int(b) - 1
            ps = S[b]
            S[b] = c
            segtree[ord(ps) - ord('a')].update(b, 0)
            segtree[ord(c) - ord('a')].update(b, 1)
        elif a == 2:
            b, c = int(b) - 1, int(c)
            count = 0
            for i in range(26):
                count += segtree[i].query(b, c)
            ans.append(count)

    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    solve()
