class Binary_Indexed_Tree:

    def __init__(self, n):

        self.size = n

        self.tree = [0 for _ in range(n+1)]



    # a[i]にxを加算(1 <= i <= n) 1-indexed

    def add(self, i, x):

        while i <= self.size:

            self.tree[i] += x

            i += i & (-i)



    # a[1] から a[t] までの合計を得る (1 <= t <= n)

    def sum(self, i):

        s = 0

        while i > 0:

            s += self.tree[i]

            i -= i & (-i)



        return s



alpha_small_dict = {chr(i):i-97 for i in range(97, 97+26)} #辞書ver

n = int(eval(input()))

S = eval(input())

data = [[0 for i in range(n)] for j in range(26)]



bit = [Binary_Indexed_Tree(n) for i in range(26)]

for i,x in enumerate(S):

    bit[alpha_small_dict[x]].add(i+1,1)

    data[alpha_small_dict[x]][i] = 1

q = int(eval(input()))

for i in range(q):

    x,y,z = input().split()

    x,y = int(x),int(y)

    #print(x,y,z)

    if x == 1:

        num = alpha_small_dict[z]

        for j in range(26):

            if data[j][y-1] == 1:

                data[j][y-1] = 0

                bit[j].add(y,-1)

                break

        data[num][y-1] = 1

        bit[num].add(y,1)

    else:

        z = int(z)

        ans = 0

        for j in range(26):

            if bit[j].sum(z)-bit[j].sum(y-1) >= 1:

                ans += 1

        print(ans)
class OR_seg:

    def __init__(self,n,init_val,ide_ele = 0):

        # set_val

        self.ide_ele = ide_ele

        self.n = n

        self.num = 2 ** (self.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]

            # built

        for i in range(self.num - 2, -1, -1):

            self.seg[i] = 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 + 1:

            k = (k - 1) // 2

            self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 2]



    def add(self,k, x):

        k += self.num - 1

        self.seg[k] += x

        while k + 1:

            k = (k - 1) // 2

            self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 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.seg[p]



            if q & 1 == 1:

                res |= self.seg[q]

                q -= 1

            p = p // 2

            q = (q - 1) // 2



        res = res | self.seg[p]|self.seg[q]



        return res

def bit_count(x): #立ってるビットの本数を出力

    n = 0

    while x:

        n += 1

        x &= x-1



    return n



alpha_small_dict = {chr(i):i-97 for i in range(97, 97+26)} #辞書ver

n = int(eval(input()))

S = eval(input())

init = [2**alpha_small_dict[x] for x in S]

#print(init)

seg = OR_seg(n,init)

q = int(eval(input()))

for i in range(q):

    x,y,z = input().split()

    x,y = int(x),int(y)

    #print(x,y,z)

    if x == 1:

        num = alpha_small_dict[z]

        seg.update(y-1,2**num)

    else:

        z = int(z)

        ans = seg.query(y-1,z)

        print((bit_count(ans)))
class Binary_Indexed_Tree:
    def __init__(self, n):
        self.size = n
        self.tree = [0 for _ in range(n + 1)]

    # a[i]にxを加算(1 <= i <= n) 1-indexed
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & (-i)

    # a[1] から a[t] までの合計を得る (1 <= t <= n)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & (-i)
        return s


alpha_small_dict = {chr(i): i - 97 for i in range(97, 97 + 26)}  # 辞書ver
n = int(eval(input()))
S = eval(input())
data = [[0 for i in range(n)] for j in range(26)]
bit = [Binary_Indexed_Tree(n) for i in range(26)]
for i, x in enumerate(S):
    bit[alpha_small_dict[x]].add(i + 1, 1)
    data[alpha_small_dict[x]][i] = 1
q = int(eval(input()))
for i in range(q):
    x, y, z = input().split()
    x, y = int(x), int(y)
    # print(x,y,z)
    if x == 1:
        num = alpha_small_dict[z]
        for j in range(26):
            if data[j][y - 1] == 1:
                data[j][y - 1] = 0
                bit[j].add(y, -1)
                break
        data[num][y - 1] = 1
        bit[num].add(y, 1)
    else:
        z = int(z)
        ans = 0
        for j in range(26):
            if bit[j].sum(z) - bit[j].sum(y - 1) >= 1:
                ans += 1
        print(ans)

class OR_seg:
    def __init__(self, n, init_val, ide_ele=0):
        # set_val
        self.ide_ele = ide_ele
        self.n = n
        self.num = 2 ** (self.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]
            # built
        for i in range(self.num - 2, -1, -1):
            self.seg[i] = 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 + 1:
            k = (k - 1) // 2
            self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 2]

    def add(self, k, x):
        k += self.num - 1
        self.seg[k] += x
        while k + 1:
            k = (k - 1) // 2
            self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 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.seg[p]
            if q & 1 == 1:
                res |= self.seg[q]
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        res = res | self.seg[p] | self.seg[q]
        return res


def bit_count(x):  # 立ってるビットの本数を出力
    n = 0
    while x:
        n += 1
        x &= x - 1
    return n


alpha_small_dict = {chr(i): i - 97 for i in range(97, 97 + 26)}  # 辞書ver
n = int(eval(input()))
S = eval(input())
init = [2 ** alpha_small_dict[x] for x in S]
# print(init)
seg = OR_seg(n, init)
q = int(eval(input()))
for i in range(q):
    x, y, z = input().split()
    x, y = int(x), int(y)
    # print(x,y,z)
    if x == 1:
        num = alpha_small_dict[z]
        seg.update(y - 1, 2**num)
    else:
        z = int(z)
        ans = seg.query(y - 1, z)
        print((bit_count(ans)))

-class Binary_Indexed_Tree: -    def __init__(self, n): -        self.size = n -        self.tree = [0 for _ in range(n + 1)] +class OR_seg: +    def __init__(self, n, init_val, ide_ele=0): +        # set_val +        self.ide_ele = ide_ele +        self.n = n +        self.num = 2 ** (self.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] +            # built +        for i in range(self.num - 2, -1, -1): +            self.seg[i] = self.seg[2 * i + 1] | self.seg[2 * i + 2] -    # a[i]にxを加算(1 <= i <= n) 1-indexed -    def add(self, i, x): -        while i <= self.size: -            self.tree[i] += x -            i += i & (-i) +    def update(self, k, x): +        k += self.num - 1 +        self.seg[k] = x +        while k + 1: +            k = (k - 1) // 2 +            self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 2] -    # a[1] から a[t] までの合計を得る (1 <= t <= n) -    def sum(self, i): -        s = 0 -        while i > 0: -            s += self.tree[i] -            i -= i & (-i) -        return s +    def add(self, k, x): +        k += self.num - 1 +        self.seg[k] += x +        while k + 1: +            k = (k - 1) // 2 +            self.seg[k] = self.seg[2 * k + 1] | self.seg[2 * k + 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.seg[p] +            if q & 1 == 1: +                res |= self.seg[q] +                q -= 1 +            p = p // 2 +            q = (q - 1) // 2 +        res = res | self.seg[p] | self.seg[q] +        return res + + +def bit_count(x):  # 立ってるビットの本数を出力 +    n = 0 +    while x: +        n += 1 +        x &= x - 1 +    return n -data = [[0 for i in range(n)] for j in range(26)] -bit = [Binary_Indexed_Tree(n) for i in range(26)] -for i, x in enumerate(S): -    bit[alpha_small_dict[x]].add(i + 1, 1) -    data[alpha_small_dict[x]][i] = 1 +init = [2 ** alpha_small_dict[x] for x in S] +# print(init) +seg = OR_seg(n, init) -        for j in range(26): -            if data[j][y - 1] == 1: -                data[j][y - 1] = 0 -                bit[j].add(y, -1) -                break -        data[num][y - 1] = 1 -        bit[num].add(y, 1) +        seg.update(y - 1, 2**num) -        ans = 0 -        for j in range(26): -            if bit[j].sum(z) - bit[j].sum(y - 1) >= 1: -                ans += 1 -        print(ans) +        ans = seg.query(y - 1, z) +        print((bit_count(ans)))