class SegTree():

    def __init__(self, lists, function, basement):

        self.n = len(lists)

        self.K = (self.n-1).bit_length()

        self.f = function

        self.b = basement

        self.seg = [basement]*2**(self.K+1)

        self.lazy_seg = [basement]*2**(self.K+1)

        X = 2**self.K

        for i, v in enumerate(lists):

            self.seg[i+X-1] = v



        for i in range(2*X-2, 0, -2):

            self.seg[(i-1) >> 1] = self.f(self.seg[i], self.seg[i-1])



    def update(self, k, value):

        # 0-indexでa[k]の値をvalueに変更

        X = 2**self.K

        k += X-1

        self.seg[k] = value

        while k:

            k = (k-1) >> 1

            self.seg[k] = self.f(self.seg[(k << 1)+1], self.seg[(k << 1)+2])





    def query(self, L, R):

        # 0-index で[L,R)

        num = 2**self.K-1

        L += num

        R += num

        vL = self.b

        vR = self.b

        while L < R:

            if L & 1 == 0:

                vL = self.f(vL, self.seg[L])

                L += 1

            if R & 1 == 0:

                R -= 1

                vR = self.f(self.seg[R], vR)

            L >>= 1

            R >>= 1

        return self.f(vL, vR)



import sys

input=sys.stdin.readline

N=int(eval(input()))

S=list(eval(input()))

Q=int(eval(input()))

que=[tuple(input().split()) for i in range(Q)]

alpha="abcdefghijklmnopqrstuvwxyz"

Data={alpha[i]:[0]*N for i in range(26)}

for i in range(N):

    Data[S[i]][i]+=1

SEG={alpha[i]:SegTree(Data[alpha[i]],max,0) for i in range(26)}

for X,u,v in que:

    if X=="1":

        u=int(u)-1

        NOW=S[u]

        S[u]=v

        SEG[NOW].update(u,0)

        SEG[v].update(u,1)

    else:

        u,v=int(u)-1,int(v)-1

        res=0

        for j in range(26):

            res+=SEG[alpha[j]].query(u,v+1)

        print(res)

            

        

    

    

import sys





class SegTree():

    def __init__(self, lists, function, basement):

        self.n = len(lists)

        self.K = (self.n-1).bit_length()

        self.f = function

        self.b = basement

        self.seg = [basement]*2**(self.K+1)

        X = 2**self.K

        for i, v in enumerate(lists):

            self.seg[i+X-1] = v



        for i in range(2*X-2, 0, -2):

            self.seg[(i-1) >> 1] = self.f(self.seg[i], self.seg[i-1])



    def update(self, k, value):

        X = 2**self.K

        k += X-1

        self.seg[k] = value

        while k:

            k = (k-1) >> 1

            self.seg[k] = self.f(self.seg[(k << 1)+1], self.seg[(k << 1)+2])



    def query(self, L, R):

        num = 2**self.K-1

        L += num

        R += num

        vL = self.b

        vR = self.b

        while L < R:

            if L & 1 == 0:

                vL = self.f(vL, self.seg[L])

                L += 1

            if R & 1 == 0:

                R -= 1

                vR = self.f(self.seg[R], vR)

            L >>= 1

            R >>= 1

        return self.f(vL, vR)





input = sys.stdin.readline





def main():

    N = int(eval(input()))

    S = list(eval(input()))

    Q = int(eval(input()))

    que = [tuple(input().split()) for i in range(Q)]

    alpha = "abcdefghijklmnopqrstuvwxyz"

    Data = {alpha[i]: [0]*N for i in range(26)}

    for i in range(N):

        Data[S[i]][i] += 1

    SEG = {alpha[i]: SegTree(Data[alpha[i]], max, 0) for i in range(26)}

    for X, u, v in que:

        if X == "1":

            u = int(u)-1

            NOW = S[u]

            S[u] = v

            SEG[NOW].update(u, 0)

            SEG[v].update(u, 1)

        else:

            u, v = int(u)-1, int(v)-1

            res = 0

            for j in range(26):

                res += SEG[alpha[j]].query(u, v+1)

            print(res)





if __name__ == "__main__":

    main()
class SegTree:
    def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n - 1).bit_length()
        self.f = function
        self.b = basement
        self.seg = [basement] * 2 ** (self.K + 1)
        self.lazy_seg = [basement] * 2 ** (self.K + 1)
        X = 2**self.K
        for i, v in enumerate(lists):
            self.seg[i + X - 1] = v
        for i in range(2 * X - 2, 0, -2):
            self.seg[(i - 1) >> 1] = self.f(self.seg[i], self.seg[i - 1])

    def update(self, k, value):
        # 0-indexでa[k]の値をvalueに変更
        X = 2**self.K
        k += X - 1
        self.seg[k] = value
        while k:
            k = (k - 1) >> 1
            self.seg[k] = self.f(self.seg[(k << 1) + 1], self.seg[(k << 1) + 2])

    def query(self, L, R):
        # 0-index で[L,R)
        num = 2**self.K - 1
        L += num
        R += num
        vL = self.b
        vR = self.b
        while L < R:
            if L & 1 == 0:
                vL = self.f(vL, self.seg[L])
                L += 1
            if R & 1 == 0:
                R -= 1
                vR = self.f(self.seg[R], vR)
            L >>= 1
            R >>= 1
        return self.f(vL, vR)


import sys

input = sys.stdin.readline
N = int(eval(input()))
S = list(eval(input()))
Q = int(eval(input()))
que = [tuple(input().split()) for i in range(Q)]
alpha = "abcdefghijklmnopqrstuvwxyz"
Data = {alpha[i]: [0] * N for i in range(26)}
for i in range(N):
    Data[S[i]][i] += 1
SEG = {alpha[i]: SegTree(Data[alpha[i]], max, 0) for i in range(26)}
for X, u, v in que:
    if X == "1":
        u = int(u) - 1
        NOW = S[u]
        S[u] = v
        SEG[NOW].update(u, 0)
        SEG[v].update(u, 1)
    else:
        u, v = int(u) - 1, int(v) - 1
        res = 0
        for j in range(26):
            res += SEG[alpha[j]].query(u, v + 1)
        print(res)

import sys


class SegTree:
    def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n - 1).bit_length()
        self.f = function
        self.b = basement
        self.seg = [basement] * 2 ** (self.K + 1)
        X = 2**self.K
        for i, v in enumerate(lists):
            self.seg[i + X - 1] = v
        for i in range(2 * X - 2, 0, -2):
            self.seg[(i - 1) >> 1] = self.f(self.seg[i], self.seg[i - 1])

    def update(self, k, value):
        X = 2**self.K
        k += X - 1
        self.seg[k] = value
        while k:
            k = (k - 1) >> 1
            self.seg[k] = self.f(self.seg[(k << 1) + 1], self.seg[(k << 1) + 2])

    def query(self, L, R):
        num = 2**self.K - 1
        L += num
        R += num
        vL = self.b
        vR = self.b
        while L < R:
            if L & 1 == 0:
                vL = self.f(vL, self.seg[L])
                L += 1
            if R & 1 == 0:
                R -= 1
                vR = self.f(self.seg[R], vR)
            L >>= 1
            R >>= 1
        return self.f(vL, vR)


input = sys.stdin.readline


def main():
    N = int(eval(input()))
    S = list(eval(input()))
    Q = int(eval(input()))
    que = [tuple(input().split()) for i in range(Q)]
    alpha = "abcdefghijklmnopqrstuvwxyz"
    Data = {alpha[i]: [0] * N for i in range(26)}
    for i in range(N):
        Data[S[i]][i] += 1
    SEG = {alpha[i]: SegTree(Data[alpha[i]], max, 0) for i in range(26)}
    for X, u, v in que:
        if X == "1":
            u = int(u) - 1
            NOW = S[u]
            S[u] = v
            SEG[NOW].update(u, 0)
            SEG[v].update(u, 1)
        else:
            u, v = int(u) - 1, int(v) - 1
            res = 0
            for j in range(26):
                res += SEG[alpha[j]].query(u, v + 1)
            print(res)


if __name__ == "__main__":
    main()

+import sys + + -        self.lazy_seg = [basement] * 2 ** (self.K + 1) -        # 0-indexでa[k]の値をvalueに変更 -        # 0-index で[L,R) -import sys +input = sys.stdin.readline -input = sys.stdin.readline -N = int(eval(input())) -S = list(eval(input())) -Q = int(eval(input())) -que = [tuple(input().split()) for i in range(Q)] -alpha = "abcdefghijklmnopqrstuvwxyz" -Data = {alpha[i]: [0] * N for i in range(26)} -for i in range(N): -    Data[S[i]][i] += 1 -SEG = {alpha[i]: SegTree(Data[alpha[i]], max, 0) for i in range(26)} -for X, u, v in que: -    if X == "1": -        u = int(u) - 1 -        NOW = S[u] -        S[u] = v -        SEG[NOW].update(u, 0) -        SEG[v].update(u, 1) -    else: -        u, v = int(u) - 1, int(v) - 1 -        res = 0 -        for j in range(26): -            res += SEG[alpha[j]].query(u, v + 1) -        print(res) + +def main(): +    N = int(eval(input())) +    S = list(eval(input())) +    Q = int(eval(input())) +    que = [tuple(input().split()) for i in range(Q)] +    alpha = "abcdefghijklmnopqrstuvwxyz" +    Data = {alpha[i]: [0] * N for i in range(26)} +    for i in range(N): +        Data[S[i]][i] += 1 +    SEG = {alpha[i]: SegTree(Data[alpha[i]], max, 0) for i in range(26)} +    for X, u, v in que: +        if X == "1": +            u = int(u) - 1 +            NOW = S[u] +            S[u] = v +            SEG[NOW].update(u, 0) +            SEG[v].update(u, 1) +        else: +            u, v = int(u) - 1, int(v) - 1 +            res = 0 +            for j in range(26): +                res += SEG[alpha[j]].query(u, v + 1) +            print(res) + + +if __name__ == "__main__": +    main()