class SegmentTree():

    def __init__(self,n,ide_ele,merge_func):

        self.n=n

        self.ide_ele=ide_ele

        self.merge_func=merge_func

        self.val=[0 for i in range(1<<n)]

        self.merge=[0 for i in range(1<<n)]



    def update(self,id,x):

        stack=[]

        pos=1<<(self.n-1)

        while pos-1!=id:

            stack.append(pos)

            if pos-1>id:

                pos-=((pos)&(-pos))//2

            else:

                pos+=((pos)&(-pos))//2



        stack.append(pos)

        self.val[pos-1]=x

        for pos in stack[::-1]:

            if pos%2:

                self.merge[pos-1]=self.val[pos-1]

            else:

                gap=((pos)&(-pos))//2

                r=pos+gap

                l=pos-gap

                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[r-1],self.merge[l-1])



    def cnt(self,k):

        lsb=(k)&(-k)

        return (lsb<<1)-1



    def lower_kth_merge(self,nd,k):

        res=self.ide_ele

        id=nd

        if k==-1:

            return res

        while True:

            if not id%2:

                gap=((id)&(-id))//2

                l=id-gap

                r=id+gap

                cnt=self.cnt(l)

                if cnt<k:

                    k-=cnt+1

                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])

                    id=r

                elif cnt==k:

                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])

                    return res

                else:

                    id=l

            else:

                res=self.merge_func(res,self.val[id-1])

                return res



    def upper_kth_merge(self,nd,k):

        res=self.ide_ele

        id=nd

        if k==-1:

            return res

        while True:

            if not id%2:

                gap=((id)&(-id))//2

                l=id-gap

                r=id+gap

                cnt=self.cnt(r)

                if cnt<k:

                    k-=cnt+1

                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])

                    id=l

                elif cnt==k:

                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])

                    return res

                else:

                    id=r

            else:

                res=self.merge_func(res,self.val[id-1])

                return res



    def query(self,l,r):

        id=1<<(self.n-1)

        while True:

            if id-1<l:

                id+=((id)&(-id))//2

            elif id-1>r:

                id-=((id)&(-id))//2

            else:

                res=self.val[id-1]

                if id%2:

                    return res

                gap=((id)&(-id))//2

                L,R=id-gap,id+gap

                #print(l,r,id,L,R)

                left=self.upper_kth_merge(L,id-1-l-1)

                right=self.lower_kth_merge(R,r-id)

                return self.merge_func(res,left,right)



ide_ele=0



def seg_func(*args):

    res=ide_ele

    for val in args:

        res|=val

    return res



def popcount(x):

    x = x - ((x >> 1) & 0x55555555)

    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f

    x = x + (x >> 8)

    x = x + (x >> 16)

    return x & 0x0000007f



import sys



input=sys.stdin.readline



N=int(eval(input()))

S=input().rstrip()



test=SegmentTree(19,ide_ele,seg_func)

for i in range(N):

    val=ord(S[i])-97

    test.update(i,1<<val)



for _ in range(int(eval(input()))):

    t,l,r=input().split()

    t,l=int(t),int(l)

    if t==1:

        val=ord(r)-97

        test.update(l-1,1<<val)

    else:

        r=int(r)

        res=test.query(l-1,r-1)

        print((popcount(res)))
def segfunc(x,y):

    return x|y



def init(init_val):

    #set_val

    for i in range(n):

        seg[i+num-1]=init_val[i]

    #built

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

        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])



def update(k,x):

    k += num-1

    seg[k] = x

    while k:

        k = (k-1)//2

        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])



def query(p,q):

    if q<=p:

        return ide_ele

    p += num-1

    q += num-2

    res=ide_ele

    while q-p>1:

        if p&1 == 0:

            res = segfunc(res,seg[p])

        if q&1 == 1:

            res = segfunc(res,seg[q])

            q -= 1

        p = p//2

        q = (q-1)//2

    if p == q:

        res = segfunc(res,seg[p])

    else:

        res = segfunc(segfunc(res,seg[p]),seg[q])

    return res



#####単位元######

ide_ele = 0



#num:n以上の最小の2のべき乗

n=int(eval(input()))

S=eval(input())

Q=int(eval(input()))



num =2**(n-1).bit_length()

seg=[ide_ele]*2*num



alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

alphabet={key:alphabetlist.index(key)  for key in alphabetlist}



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

for i in range(0,n):

    data[i]=2**(alphabet[S[i]])



init(data)



ans=[]

for i in range(0,Q):

    q,a,b=input().split()

    if q=='1':

        update(int(a)-1,2**(alphabet[b]))

    else:

        a=int(a)

        b=int(b)

        ans.append(query(a-1,b))



for i in range(len(ans)):

    x=ans[i]

    print((bin(x).count('1')))

class SegmentTree:
    def __init__(self, n, ide_ele, merge_func):
        self.n = n
        self.ide_ele = ide_ele
        self.merge_func = merge_func
        self.val = [0 for i in range(1 << n)]
        self.merge = [0 for i in range(1 << n)]

    def update(self, id, x):
        stack = []
        pos = 1 << (self.n - 1)
        while pos - 1 != id:
            stack.append(pos)
            if pos - 1 > id:
                pos -= ((pos) & (-pos)) // 2
            else:
                pos += ((pos) & (-pos)) // 2
        stack.append(pos)
        self.val[pos - 1] = x
        for pos in stack[::-1]:
            if pos % 2:
                self.merge[pos - 1] = self.val[pos - 1]
            else:
                gap = ((pos) & (-pos)) // 2
                r = pos + gap
                l = pos - gap
                self.merge[pos - 1] = self.merge_func(
                    self.val[pos - 1], self.merge[r - 1], self.merge[l - 1]
                )

    def cnt(self, k):
        lsb = (k) & (-k)
        return (lsb << 1) - 1

    def lower_kth_merge(self, nd, k):
        res = self.ide_ele
        id = nd
        if k == -1:
            return res
        while True:
            if not id % 2:
                gap = ((id) & (-id)) // 2
                l = id - gap
                r = id + gap
                cnt = self.cnt(l)
                if cnt < k:
                    k -= cnt + 1
                    res = self.merge_func(res, self.val[id - 1], self.merge[l - 1])
                    id = r
                elif cnt == k:
                    res = self.merge_func(res, self.val[id - 1], self.merge[l - 1])
                    return res
                else:
                    id = l
            else:
                res = self.merge_func(res, self.val[id - 1])
                return res

    def upper_kth_merge(self, nd, k):
        res = self.ide_ele
        id = nd
        if k == -1:
            return res
        while True:
            if not id % 2:
                gap = ((id) & (-id)) // 2
                l = id - gap
                r = id + gap
                cnt = self.cnt(r)
                if cnt < k:
                    k -= cnt + 1
                    res = self.merge_func(res, self.val[id - 1], self.merge[r - 1])
                    id = l
                elif cnt == k:
                    res = self.merge_func(res, self.val[id - 1], self.merge[r - 1])
                    return res
                else:
                    id = r
            else:
                res = self.merge_func(res, self.val[id - 1])
                return res

    def query(self, l, r):
        id = 1 << (self.n - 1)
        while True:
            if id - 1 < l:
                id += ((id) & (-id)) // 2
            elif id - 1 > r:
                id -= ((id) & (-id)) // 2
            else:
                res = self.val[id - 1]
                if id % 2:
                    return res
                gap = ((id) & (-id)) // 2
                L, R = id - gap, id + gap
                # print(l,r,id,L,R)
                left = self.upper_kth_merge(L, id - 1 - l - 1)
                right = self.lower_kth_merge(R, r - id)
                return self.merge_func(res, left, right)


ide_ele = 0


def seg_func(*args):
    res = ide_ele
    for val in args:
        res |= val
    return res


def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0F0F0F0F
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007F


import sys

input = sys.stdin.readline
N = int(eval(input()))
S = input().rstrip()
test = SegmentTree(19, ide_ele, seg_func)
for i in range(N):
    val = ord(S[i]) - 97
    test.update(i, 1 << val)
for _ in range(int(eval(input()))):
    t, l, r = input().split()
    t, l = int(t), int(l)
    if t == 1:
        val = ord(r) - 97
        test.update(l - 1, 1 << val)
    else:
        r = int(r)
        res = test.query(l - 1, r - 1)
        print((popcount(res)))

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


def init(init_val):
    # set_val
    for i in range(n):
        seg[i + num - 1] = init_val[i]
    # built
    for i in range(num - 2, -1, -1):
        seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])


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


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


#####単位元######
ide_ele = 0
# num:n以上の最小の2のべき乗
n = int(eval(input()))
S = eval(input())
Q = int(eval(input()))
num = 2 ** (n - 1).bit_length()
seg = [ide_ele] * 2 * num
alphabetlist = [
    "a",
    "b",
    "c",
    "d",
    "e",
    "f",
    "g",
    "h",
    "i",
    "j",
    "k",
    "l",
    "m",
    "n",
    "o",
    "p",
    "q",
    "r",
    "s",
    "t",
    "u",
    "v",
    "w",
    "x",
    "y",
    "z",
]
alphabet = {key: alphabetlist.index(key) for key in alphabetlist}
data = [0 for i in range(0, n)]
for i in range(0, n):
    data[i] = 2 ** (alphabet[S[i]])
init(data)
ans = []
for i in range(0, Q):
    q, a, b = input().split()
    if q == "1":
        update(int(a) - 1, 2 ** (alphabet[b]))
    else:
        a = int(a)
        b = int(b)
        ans.append(query(a - 1, b))
for i in range(len(ans)):
    x = ans[i]
    print((bin(x).count("1")))

-class SegmentTree: -    def __init__(self, n, ide_ele, merge_func): -        self.n = n -        self.ide_ele = ide_ele -        self.merge_func = merge_func -        self.val = [0 for i in range(1 << n)] -        self.merge = [0 for i in range(1 << n)] - -    def update(self, id, x): -        stack = [] -        pos = 1 << (self.n - 1) -        while pos - 1 != id: -            stack.append(pos) -            if pos - 1 > id: -                pos -= ((pos) & (-pos)) // 2 -            else: -                pos += ((pos) & (-pos)) // 2 -        stack.append(pos) -        self.val[pos - 1] = x -        for pos in stack[::-1]: -            if pos % 2: -                self.merge[pos - 1] = self.val[pos - 1] -            else: -                gap = ((pos) & (-pos)) // 2 -                r = pos + gap -                l = pos - gap -                self.merge[pos - 1] = self.merge_func( -                    self.val[pos - 1], self.merge[r - 1], self.merge[l - 1] -                ) - -    def cnt(self, k): -        lsb = (k) & (-k) -        return (lsb << 1) - 1 - -    def lower_kth_merge(self, nd, k): -        res = self.ide_ele -        id = nd -        if k == -1: -            return res -        while True: -            if not id % 2: -                gap = ((id) & (-id)) // 2 -                l = id - gap -                r = id + gap -                cnt = self.cnt(l) -                if cnt < k: -                    k -= cnt + 1 -                    res = self.merge_func(res, self.val[id - 1], self.merge[l - 1]) -                    id = r -                elif cnt == k: -                    res = self.merge_func(res, self.val[id - 1], self.merge[l - 1]) -                    return res -                else: -                    id = l -            else: -                res = self.merge_func(res, self.val[id - 1]) -                return res - -    def upper_kth_merge(self, nd, k): -        res = self.ide_ele -        id = nd -        if k == -1: -            return res -        while True: -            if not id % 2: -                gap = ((id) & (-id)) // 2 -                l = id - gap -                r = id + gap -                cnt = self.cnt(r) -                if cnt < k: -                    k -= cnt + 1 -                    res = self.merge_func(res, self.val[id - 1], self.merge[r - 1]) -                    id = l -                elif cnt == k: -                    res = self.merge_func(res, self.val[id - 1], self.merge[r - 1]) -                    return res -                else: -                    id = r -            else: -                res = self.merge_func(res, self.val[id - 1]) -                return res - -    def query(self, l, r): -        id = 1 << (self.n - 1) -        while True: -            if id - 1 < l: -                id += ((id) & (-id)) // 2 -            elif id - 1 > r: -                id -= ((id) & (-id)) // 2 -            else: -                res = self.val[id - 1] -                if id % 2: -                    return res -                gap = ((id) & (-id)) // 2 -                L, R = id - gap, id + gap -                # print(l,r,id,L,R) -                left = self.upper_kth_merge(L, id - 1 - l - 1) -                right = self.lower_kth_merge(R, r - id) -                return self.merge_func(res, left, right) +def segfunc(x, y): +    return x | y -ide_ele = 0 +def init(init_val): +    # set_val +    for i in range(n): +        seg[i + num - 1] = init_val[i] +    # built +    for i in range(num - 2, -1, -1): +        seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2]) -def seg_func(*args): +def update(k, x): +    k += num - 1 +    seg[k] = x +    while k: +        k = (k - 1) // 2 +        seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2]) + + +def query(p, q): +    if q <= p: +        return ide_ele +    p += num - 1 +    q += num - 2 -    for val in args: -        res |= val +    while q - p > 1: +        if p & 1 == 0: +            res = segfunc(res, seg[p]) +        if q & 1 == 1: +            res = segfunc(res, seg[q]) +            q -= 1 +        p = p // 2 +        q = (q - 1) // 2 +    if p == q: +        res = segfunc(res, seg[p]) +    else: +        res = segfunc(segfunc(res, seg[p]), seg[q]) -def popcount(x): -    x = x - ((x >> 1) & 0x55555555) -    x = (x & 0x33333333) + ((x >> 2) & 0x33333333) -    x = (x + (x >> 4)) & 0x0F0F0F0F -    x = x + (x >> 8) -    x = x + (x >> 16) -    return x & 0x0000007F - - -import sys - -input = sys.stdin.readline -N = int(eval(input())) -S = input().rstrip() -test = SegmentTree(19, ide_ele, seg_func) -for i in range(N): -    val = ord(S[i]) - 97 -    test.update(i, 1 << val) -for _ in range(int(eval(input()))): -    t, l, r = input().split() -    t, l = int(t), int(l) -    if t == 1: -        val = ord(r) - 97 -        test.update(l - 1, 1 << val) +#####単位元###### +ide_ele = 0 +# num:n以上の最小の2のべき乗 +n = int(eval(input())) +S = eval(input()) +Q = int(eval(input())) +num = 2 ** (n - 1).bit_length() +seg = [ide_ele] * 2 * num +alphabetlist = [ +    "a", +    "b", +    "c", +    "d", +    "e", +    "f", +    "g", +    "h", +    "i", +    "j", +    "k", +    "l", +    "m", +    "n", +    "o", +    "p", +    "q", +    "r", +    "s", +    "t", +    "u", +    "v", +    "w", +    "x", +    "y", +    "z", +] +alphabet = {key: alphabetlist.index(key) for key in alphabetlist} +data = [0 for i in range(0, n)] +for i in range(0, n): +    data[i] = 2 ** (alphabet[S[i]]) +init(data) +ans = [] +for i in range(0, Q): +    q, a, b = input().split() +    if q == "1": +        update(int(a) - 1, 2 ** (alphabet[b])) -        r = int(r) -        res = test.query(l - 1, r - 1) -        print((popcount(res))) +        a = int(a) +        b = int(b) +        ans.append(query(a - 1, b)) +for i in range(len(ans)): +    x = ans[i] +    print((bin(x).count("1")))