from math import log2, ceil


class SegTree:
    #####単位元######
    ide_ele = 0

    def __init__(self, init_val):
        n = len(init_val)
        self.num = 2**ceil(log2(n))
        self.seg = [self.ide_ele] * (2 * self.num - 1)

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

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

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

    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, a, b, k, l, r):
        if r <= a or b <= l:
            return self.ide_ele
        if a <= l and r <= b:
            return self.seg[k]
        else:
            vl = self.query(a, b, k*2+1, l, (l+r)//2)
            vr = self.query(a, b, k*2+2, (l+r)//2, r)
            return self.segfunc(vl, vr)


N = int(input())
S = input()
Q = int(input())

li = [1 << (ord(s) - ord('a')) for s in S]
seg_tree = SegTree(li)
ans = []
for _ in range(Q):
    i, l, r = input().split()
    i = int(i)
    l = int(l)
    if i == 1:
        seg_tree.update(l-1, 1 << (ord(r) - ord('a')))
    else:
        r = int(r)
        num = seg_tree.query(l-1, r, 0, 0, seg_tree.num)
        ans.append(bin(num).count('1'))

for a in ans:
    print(a) from math import log2, ceil class SegTree:
    #####単位元######
    ide_ele = 0

    def __init__(self, init_val):
        n = len(init_val)
        self.num = 2**ceil(log2(n))
        self.seg = [self.ide_ele] * (2 * self.num - 1)

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

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

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

    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, a, b, k, l, r):
        if r <= a or b <= l:
            return self.ide_ele
        if a <= l and r <= b:
            return self.seg[k]
        else:
            vl = self.query(a, b, k*2+1, l, (l+r)//2)
            vr = self.query(a, b, k*2+2, (l+r)//2, r)
            return self.segfunc(vl, vr) SegTree ide_ele = 0 ide_ele 0 def __init__(self, init_val):
        n = len(init_val)
        self.num = 2**ceil(log2(n))
        self.seg = [self.ide_ele] * (2 * self.num - 1)

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

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

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

        # built
         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])

    #####segfunc######
     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 def segfunc(self, x, y):
        return x|y

     segfunc return x|y x|y x y self self x x y y 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, a, b, k, l, r):
        if r <= a or b <= l:
            return self.ide_ele
        if a <= l and r <= b:
            return self.seg[k]
        else:
            vl = self.query(a, b, k*2+1, l, (l+r)//2)
            vr = self.query(a, b, k*2+2, (l+r)//2, r)
            return self.segfunc(vl, vr) query if r <= a or b <= l:
            return self.ide_ele
         r <= a or b <= l r <= a r a b <= l b l return self.ide_ele self.ide_ele self ide_ele if a <= l and r <= b:
            return self.seg[k]
        else:
            vl = self.query(a, b, k*2+1, l, (l+r)//2)
            vr = self.query(a, b, k*2+2, (l+r)//2, r)
            return self.segfunc(vl, vr) a <= l and r <= b a <= l a l r <= b r b return self.seg[k] self.seg[k] self.seg self seg k vl = self.query(a, b, k*2+1, l, (l+r)//2) vl self.query(a, b, k*2+1, l, (l+r)//2) self.query self query a b k*2+1 k*2 k 2 1 l (l+r)//2 l+r l r 2 vr = self.query(a, b, k*2+2, (l+r)//2, r) vr self.query(a, b, k*2+2, (l+r)//2, r) self.query self query a b k*2+2 k*2 k 2 2 (l+r)//2 l+r l r 2 r return self.segfunc(vl, vr) self.segfunc(vl, vr) self.segfunc self segfunc vl vr self self a a b b k k l l r r N = int(input()) N int(input()) int input() input S = input() S input() input Q = int(input()) Q int(input()) int input() input 1 << (ord(s) - ord('a')) for s in S for s in S s S for s in S 1 << (ord(s) - ord('a')) 1 ord(s) - ord('a') ord(s) ord s ord('a') ord 'a' li = [1 << (ord(s) - ord('a')) for s in S] li [1 << (ord(s) - ord('a')) for s in S] seg_tree = SegTree(li) seg_tree SegTree(li) SegTree li ans = [] ans [] for _ in range(Q):
    i, l, r = input().split()
    i = int(i)
    l = int(l)
    if i == 1:
        seg_tree.update(l-1, 1 << (ord(r) - ord('a')))
    else:
        r = int(r)
        num = seg_tree.query(l-1, r, 0, 0, seg_tree.num)
        ans.append(bin(num).count('1')) _ range(Q) range Q i, l, r = input().split() i input().split() ().split () input split l r i = int(i) i int(i) int i l = int(l) l int(l) int l if i == 1:
        seg_tree.update(l-1, 1 << (ord(r) - ord('a')))
    else:
        r = int(r)
        num = seg_tree.query(l-1, r, 0, 0, seg_tree.num)
        ans.append(bin(num).count('1')) i == 1 i 1 seg_tree.update(l-1, 1 << (ord(r) - ord('a'))) seg_tree.update seg_tree update l-1 l 1 1 << (ord(r) - ord('a')) 1 ord(r) - ord('a') ord(r) ord r ord('a') ord 'a' r = int(r) r int(r) int r num = seg_tree.query(l-1, r, 0, 0, seg_tree.num) num seg_tree.query(l-1, r, 0, 0, seg_tree.num) seg_tree.query seg_tree query l-1 l 1 r 0 0 seg_tree.num seg_tree num ans.append(bin(num).count('1')) ans.append ans append bin(num).count('1') (num).count (num) bin num count '1' for a in ans:
    print(a) a ans print(a) print a class SegTree:
    #####単位元######
    ide_ele = 0

    def __init__(self, init_val):
        n = len(init_val)
        self.num = 2**ceil(log2(n))
        self.seg = [self.ide_ele] * (2 * self.num - 1)

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

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

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

    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, a, b, k, l, r):
        if r <= a or b <= l:
            return self.ide_ele
        if a <= l and r <= b:
            return self.seg[k]
        else:
            vl = self.query(a, b, k*2+1, l, (l+r)//2)
            vr = self.query(a, b, k*2+2, (l+r)//2, r)
            return self.segfunc(vl, vr) class SegTree:
    #####単位元######
    ide_ele = 0

    def __init__(self, init_val):
        n = len(init_val)
        self.num = 2**ceil(log2(n))
        self.seg = [self.ide_ele] * (2 * self.num - 1)

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

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

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

    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, a, b, k, l, r):
        if r <= a or b <= l:
            return self.ide_ele
        if a <= l and r <= b:
            return self.seg[k]
        else:
            vl = self.query(a, b, k*2+1, l, (l+r)//2)
            vr = self.query(a, b, k*2+2, (l+r)//2, r)
            return self.segfunc(vl, vr) SegTree num = seg_tree.query(l-1, r, 0, 0, seg_tree.num) seg_tree.query(l-1, r, 0, 0, seg_tree.num) num li = [1 << (ord(s) - ord('a')) for s in S] [1 << (ord(s) - ord('a')) for s in S] li ans = [] [] ans l, r = input().split() input().split() l i, l, r = input().split() input().split() i seg_tree = SegTree(li) SegTree(li) seg_tree S = input() input() S r = int(r) int(r) r i = int(i) int(i) i N = int(input()) int(input()) N r = input().split() input().split() r Q = int(input()) int(input()) Q l = int(l) int(l) l
from math import log2, ceil


class SegTree:
    #####単位元######
    ide_ele = 0

    def __init__(self, init_val):
        n = len(init_val)
        self.num = 2**ceil(log2(n))
        self.seg = [self.ide_ele] * (2 * self.num - 1)

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

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

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

    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, a, b, k, l, r):
        if r <= a or b <= l:
            return self.ide_ele
        if a <= l and r <= b:
            return self.seg[k]
        else:
            vl = self.query(a, b, k*2+1, l, (l+r)//2)
            vr = self.query(a, b, k*2+2, (l+r)//2, r)
            return self.segfunc(vl, vr)


N = int(input())
S = input()
Q = int(input())

li = [1 << (ord(s) - ord('a')) for s in S]
seg_tree = SegTree(li)
ans = []
for _ in range(Q):
    i, l, r = input().split()
    i = int(i)
    l = int(l)
    if i == 1:
        seg_tree.update(l-1, 1 << (ord(r) - ord('a')))
    else:
        r = int(r)
        num = seg_tree.query(l-1, r, 0, 0, seg_tree.num)
        ans.append(bin(num).count('1'))

for a in ans:
    print(a)
