# import numpy as np

from operator import or_

class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_leaves = 2**(len(nb)-1)
        else:
            self.num_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_leaves * 2)]
        self.identity = identity
        self.operator =operator
        self.n = n

    def build(self,init_arr):
        for i in range(self.n):
            self.array[i+self.num_leaves] = init_arr[i]
        for i in range(self.num_leaves):
            pt = self.num_leaves-1-i
            self.array[pt] = self.operator(self.array[pt*2],self.array[pt*2+1])


    def update(self,x,val):
        actual_x = x+self.num_leaves
        # self.array[actual_x] = self.operator(self.array[actual_x],val)
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r)

    def find(self, l, r):
        #findの方が高速
        l += self.num_leaves
        r += self.num_leaves+1
        ret = self.identity
        while l < r:
            if l & 1:
                ret = self.operator(ret, self.array[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.operator(ret, self.array[r])
            l //= 2
            r //= 2
        return ret







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

tree = segtree(n, or_, 0)
buf = [0 for i in range(n)]

for i in range(n):
    c = ord(s[i]) - 97
    buf[i] = 1<<c


for i in range(26):
    tree.build(buf)




s = list(s)

for i in range(q):
    ty, i, c = input().split()

    if ty == "1":
        i = int(i)
        t = ord(c) - 97
        tree.update(i-1,1<<t)


    else:
        i = int(i)
        c = int(c)
        i -= 1
        c -= 1
        tp = 0
        hoge = tree.get(i,c)
        print(sum(map(int,bin(hoge)[2:]))) from operator import or_ class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_leaves = 2**(len(nb)-1)
        else:
            self.num_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_leaves * 2)]
        self.identity = identity
        self.operator =operator
        self.n = n

    def build(self,init_arr):
        for i in range(self.n):
            self.array[i+self.num_leaves] = init_arr[i]
        for i in range(self.num_leaves):
            pt = self.num_leaves-1-i
            self.array[pt] = self.operator(self.array[pt*2],self.array[pt*2+1])


    def update(self,x,val):
        actual_x = x+self.num_leaves
        # self.array[actual_x] = self.operator(self.array[actual_x],val)
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r)

    def find(self, l, r):
        #findの方が高速
        l += self.num_leaves
        r += self.num_leaves+1
        ret = self.identity
        while l < r:
            if l & 1:
                ret = self.operator(ret, self.array[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.operator(ret, self.array[r])
            l //= 2
            r //= 2
        return ret segtree def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_leaves = 2**(len(nb)-1)
        else:
            self.num_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_leaves * 2)]
        self.identity = identity
        self.operator =operator
        self.n = n

     __init__ nb = bin(n)[2:] nb bin(n)[2:] (n) bin n 2: 2 int(digit) for digit in nb for digit in nb digit nb for digit in nb int(digit) int digit bc = sum([int(digit) for digit in nb]) bc sum([int(digit) for digit in nb]) sum [int(digit) for digit in nb] if bc == 1:
            self.num_leaves = 2**(len(nb)-1)
        else:
            self.num_leaves = 2**(len(nb))

         bc == 1 bc 1 self.num_leaves = 2**(len(nb)-1) self.num_leaves self num_leaves 2**(len(nb)-1) 2 len(nb)-1 len(nb) len nb 1 self.num_leaves = 2**(len(nb)) self.num_leaves self num_leaves 2**(len(nb)) 2 len(nb) len nb identity for i in range(self.num_leaves * 2) for i in range(self.num_leaves * 2) i range(self.num_leaves * 2) range self.num_leaves * 2 self.num_leaves self num_leaves 2 for i in range(self.num_leaves * 2) identity self.array = [identity for i in range(self.num_leaves * 2)] self.array self array [identity for i in range(self.num_leaves * 2)] self.identity = identity self.identity self identity identity self.operator =operator self.operator self operator operator self.n = n self.n self n n self self n n operator operator identity identity def build(self,init_arr):
        for i in range(self.n):
            self.array[i+self.num_leaves] = init_arr[i]
        for i in range(self.num_leaves):
            pt = self.num_leaves-1-i
            self.array[pt] = self.operator(self.array[pt*2],self.array[pt*2+1])


     build for i in range(self.n):
            self.array[i+self.num_leaves] = init_arr[i]
         i range(self.n) range self.n self n self.array[i+self.num_leaves] = init_arr[i] self.array[i+self.num_leaves] self.array self array i+self.num_leaves i self.num_leaves self num_leaves init_arr[i] init_arr i for i in range(self.num_leaves):
            pt = self.num_leaves-1-i
            self.array[pt] = self.operator(self.array[pt*2],self.array[pt*2+1])


     i range(self.num_leaves) range self.num_leaves self num_leaves pt = self.num_leaves-1-i pt self.num_leaves-1-i self.num_leaves-1 self.num_leaves self num_leaves 1 i self.array[pt] = self.operator(self.array[pt*2],self.array[pt*2+1]) self.array[pt] self.array self array pt self.operator(self.array[pt*2],self.array[pt*2+1]) self.operator self operator self.array[pt*2] self.array self array pt*2 pt 2 self.array[pt*2+1] self.array self array pt*2+1 pt*2 pt 2 1 self self init_arr init_arr def update(self,x,val):
        actual_x = x+self.num_leaves
        # self.array[actual_x] = self.operator(self.array[actual_x],val)
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

     update actual_x = x+self.num_leaves actual_x x+self.num_leaves x self.num_leaves self num_leaves self.array[actual_x] = val self.array[actual_x] self.array self array actual_x val while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

     actual_x > 0 actual_x 0 actual_x = actual_x//2 actual_x actual_x//2 actual_x 2 self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1]) self.array[actual_x] self.array self array actual_x self.operator(self.array[actual_x*2],self.array[actual_x*2+1]) self.operator self operator self.array[actual_x*2] self.array self array actual_x*2 actual_x 2 self.array[actual_x*2+1] self.array self array actual_x*2+1 actual_x*2 actual_x 2 1 self self x x val val def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r)

     get width_of_floor = self.num_leaves//(2**depth) width_of_floor self.num_leaves//(2**depth) self.num_leaves self num_leaves 2**depth 2 depth leaf_right = leaf_left+width_of_floor-1 leaf_right leaf_left+width_of_floor-1 leaf_left+width_of_floor leaf_left width_of_floor 1 if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r)

     leaf_left > q_right or leaf_right < q_left leaf_left > q_right leaf_left q_right leaf_right < q_left leaf_right q_left return  self.identity self.identity self identity elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

         leaf_left >= q_left and leaf_right <= q_right leaf_left >= q_left leaf_left q_left leaf_right <= q_right leaf_right q_right return self.array[arr_ind] self.array[arr_ind] self.array self array arr_ind val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1) val_l self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1) self.get self get q_left q_right 2*arr_ind 2 arr_ind leaf_left depth+1 depth 1 val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1) val_r self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1) self.get self get q_left q_right 2*arr_ind+1 2*arr_ind 2 arr_ind 1 leaf_left+width_of_floor//2 leaf_left width_of_floor//2 width_of_floor 2 depth+1 depth 1 return self.operator(val_l,val_r) self.operator(val_l,val_r) self.operator self operator val_l val_r self self q_left q_left q_right q_right arr_ind=1 arr_ind 1 leaf_left=0 leaf_left 0 depth=0 depth 0 def find(self, l, r):
        #findの方が高速
        l += self.num_leaves
        r += self.num_leaves+1
        ret = self.identity
        while l < r:
            if l & 1:
                ret = self.operator(ret, self.array[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.operator(ret, self.array[r])
            l //= 2
            r //= 2
        return ret find l += self.num_leaves l self.num_leaves self num_leaves r += self.num_leaves+1 r self.num_leaves+1 self.num_leaves self num_leaves 1 ret = self.identity ret self.identity self identity while l < r:
            if l & 1:
                ret = self.operator(ret, self.array[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.operator(ret, self.array[r])
            l //= 2
            r //= 2
         l < r l r if l & 1:
                ret = self.operator(ret, self.array[l])
                l += 1
             l & 1 l 1 ret = self.operator(ret, self.array[l]) ret self.operator(ret, self.array[l]) self.operator self operator ret self.array[l] self.array self array l l += 1 l 1 if r & 1:
                r -= 1
                ret = self.operator(ret, self.array[r])
             r & 1 r 1 r -= 1 r 1 ret = self.operator(ret, self.array[r]) ret self.operator(ret, self.array[r]) self.operator self operator ret self.array[r] self.array self array r l //= 2 l 2 r //= 2 r 2 return ret ret self self 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 tree = segtree(n, or_, 0) tree segtree(n, or_, 0) segtree n or_ 0 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 buf = [0 for i in range(n)] buf [0 for i in range(n)] for i in range(n):
    c = ord(s[i]) - 97
    buf[i] = 1<<c i range(n) range n c = ord(s[i]) - 97 c ord(s[i]) - 97 ord(s[i]) ord s[i] s i 97 buf[i] = 1<<c buf[i] buf i 1<<c 1 c for i in range(26):
    tree.build(buf) i range(26) range 26 tree.build(buf) tree.build tree build buf s = list(s) s list(s) list s for i in range(q):
    ty, i, c = input().split()

    if ty == "1":
        i = int(i)
        t = ord(c) - 97
        tree.update(i-1,1<<t)


    else:
        i = int(i)
        c = int(c)
        i -= 1
        c -= 1
        tp = 0
        hoge = tree.get(i,c)
        print(sum(map(int,bin(hoge)[2:]))) i range(q) range q ty, i, c = input().split() ty input().split() ().split () input split i c if ty == "1":
        i = int(i)
        t = ord(c) - 97
        tree.update(i-1,1<<t)


    else:
        i = int(i)
        c = int(c)
        i -= 1
        c -= 1
        tp = 0
        hoge = tree.get(i,c)
        print(sum(map(int,bin(hoge)[2:]))) ty == "1" ty "1" i = int(i) i int(i) int i t = ord(c) - 97 t ord(c) - 97 ord(c) ord c 97 tree.update(i-1,1<<t) tree.update tree update i-1 i 1 1<<t 1 t i = int(i) i int(i) int i c = int(c) c int(c) int c i -= 1 i 1 c -= 1 c 1 tp = 0 tp 0 hoge = tree.get(i,c) hoge tree.get(i,c) tree.get tree get i c print(sum(map(int,bin(hoge)[2:]))) print sum(map(int,bin(hoge)[2:])) sum map(int,bin(hoge)[2:]) map int bin(hoge)[2:] (hoge) bin hoge 2: 2 hoge = tree.get(i,c) tree.get(i,c) hoge i, c = input().split() input().split() i i = int(i) int(i) i c = ord(s[i]) - 97 ord(s[i]) - 97 c s = list(s) list(s) s i = int(i) int(i) i class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_leaves = 2**(len(nb)-1)
        else:
            self.num_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_leaves * 2)]
        self.identity = identity
        self.operator =operator
        self.n = n

    def build(self,init_arr):
        for i in range(self.n):
            self.array[i+self.num_leaves] = init_arr[i]
        for i in range(self.num_leaves):
            pt = self.num_leaves-1-i
            self.array[pt] = self.operator(self.array[pt*2],self.array[pt*2+1])


    def update(self,x,val):
        actual_x = x+self.num_leaves
        # self.array[actual_x] = self.operator(self.array[actual_x],val)
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r)

    def find(self, l, r):
        #findの方が高速
        l += self.num_leaves
        r += self.num_leaves+1
        ret = self.identity
        while l < r:
            if l & 1:
                ret = self.operator(ret, self.array[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.operator(ret, self.array[r])
            l //= 2
            r //= 2
        return ret class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_leaves = 2**(len(nb)-1)
        else:
            self.num_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_leaves * 2)]
        self.identity = identity
        self.operator =operator
        self.n = n

    def build(self,init_arr):
        for i in range(self.n):
            self.array[i+self.num_leaves] = init_arr[i]
        for i in range(self.num_leaves):
            pt = self.num_leaves-1-i
            self.array[pt] = self.operator(self.array[pt*2],self.array[pt*2+1])


    def update(self,x,val):
        actual_x = x+self.num_leaves
        # self.array[actual_x] = self.operator(self.array[actual_x],val)
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r)

    def find(self, l, r):
        #findの方が高速
        l += self.num_leaves
        r += self.num_leaves+1
        ret = self.identity
        while l < r:
            if l & 1:
                ret = self.operator(ret, self.array[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.operator(ret, self.array[r])
            l //= 2
            r //= 2
        return ret segtree tp = 0 0 tp t = ord(c) - 97 ord(c) - 97 t q = int(input()) int(input()) q tree = segtree(n, or_, 0) segtree(n, or_, 0) tree c -= 1 1 c ty, i, c = input().split() input().split() ty s = input() input() s buf = [0 for i in range(n)] [0 for i in range(n)] buf i -= 1 1 i n = int(input()) int(input()) n c = input().split() input().split() c c = int(c) int(c) c
# import numpy as np

from operator import or_

class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_leaves = 2**(len(nb)-1)
        else:
            self.num_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_leaves * 2)]
        self.identity = identity
        self.operator =operator
        self.n = n

    def build(self,init_arr):
        for i in range(self.n):
            self.array[i+self.num_leaves] = init_arr[i]
        for i in range(self.num_leaves):
            pt = self.num_leaves-1-i
            self.array[pt] = self.operator(self.array[pt*2],self.array[pt*2+1])


    def update(self,x,val):
        actual_x = x+self.num_leaves
        # self.array[actual_x] = self.operator(self.array[actual_x],val)
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r)

    def find(self, l, r):
        #findの方が高速
        l += self.num_leaves
        r += self.num_leaves+1
        ret = self.identity
        while l < r:
            if l & 1:
                ret = self.operator(ret, self.array[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.operator(ret, self.array[r])
            l //= 2
            r //= 2
        return ret







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

tree = segtree(n, or_, 0)
buf = [0 for i in range(n)]

for i in range(n):
    c = ord(s[i]) - 97
    buf[i] = 1<<c


for i in range(26):
    tree.build(buf)




s = list(s)

for i in range(q):
    ty, i, c = input().split()

    if ty == "1":
        i = int(i)
        t = ord(c) - 97
        tree.update(i-1,1<<t)


    else:
        i = int(i)
        c = int(c)
        i -= 1
        c -= 1
        tp = 0
        hoge = tree.get(i,c)
        print(sum(map(int,bin(hoge)[2:])))
