import sys
from operator import or_
input=sys.stdin.readline


class SegTree():
    def __init__(self, N, e=float("inf"), operator_func=min):
        self.e = e
        self.size = N
        self.node = [self.e] * (2*N)
        self.op = operator_func

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size - 1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        x = self.e
        l += self.size; r += self.size
        a, b = [], []

        while l<r:
            if l&1:
                a += [l-1]; l += 1
            if r&1:
                r -= 1; b += [r-1]
            l >>= 1; r >>= 1

        for i in a+(b[::-1]):
            x = self.op(x, self.node[i])
        return x


def main():
    N = int(input())
    S = list(input())[:-1]
    trees = {chr(97+i):SegTree(N, e=0, operator_func=or_) for i in range(26)}

    for i, s in enumerate(S):
        trees[s].update(i, 1)

    Q = int(input())
    for _ in range(Q):
        mode, i, v = input().split()
        if mode=="1":
            i = int(i)-1
            trees[S[i]].update(i, 0)
            trees[v].update(i, 1)
            S[i] = v
        else:
            i = int(i)-1
            v = int(v)
            ans = sum(trees[chr(97+j)].get(i, v) for j in range(26))
            print(ans)


if __name__ == "__main__":
    main() import sys sys from operator import or_ input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline class SegTree():
    def __init__(self, N, e=float("inf"), operator_func=min):
        self.e = e
        self.size = N
        self.node = [self.e] * (2*N)
        self.op = operator_func

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size - 1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        x = self.e
        l += self.size; r += self.size
        a, b = [], []

        while l<r:
            if l&1:
                a += [l-1]; l += 1
            if r&1:
                r -= 1; b += [r-1]
            l >>= 1; r >>= 1

        for i in a+(b[::-1]):
            x = self.op(x, self.node[i])
        return x SegTree def __init__(self, N, e=float("inf"), operator_func=min):
        self.e = e
        self.size = N
        self.node = [self.e] * (2*N)
        self.op = operator_func

     __init__ self.e = e self.e self e e self.size = N self.size self size N self.node = [self.e] * (2*N) self.node self node [self.e] * (2*N) [self.e] self.e self e 2*N 2 N self.op = operator_func self.op self op operator_func self self N N e=float("inf") e float("inf") float "inf" operator_func=min operator_func min def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2])
    
     set_list for i in range(self.size):
            self.node[i+self.size-1] = l[i]
         i range(self.size) range self.size self size self.node[i+self.size-1] = l[i] self.node[i+self.size-1] self.node self node i+self.size-1 i+self.size i self.size self size 1 l[i] l i for i in range(self.size-1)[::-1]:
            self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2])
    
     i range(self.size-1)[::-1] (self.size-1) range self.size-1 self.size self size 1 ::-1 -1 self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2]) self.node[i] self.node self node i self.op(self.node[2*i+1], self.node[2*i+2]) self.op self op self.node[2*i+1] self.node self node 2*i+1 2*i 2 i 1 self.node[2*i+2] self.node self node 2*i+2 2*i 2 i 2 self self l l def update(self, k, x):
        k += self.size - 1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])

     update k += self.size - 1 k self.size - 1 self.size self size 1 self.node[k] = x self.node[k] self.node self node k x while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])

     k >= 0 k 0 k = (k - 1) // 2 k (k - 1) // 2 k - 1 k 1 2 self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2]) self.node[k] self.node self node k self.op(self.node[2*k+1], self.node[2*k+2]) self.op self op self.node[2*k+1] self.node self node 2*k+1 2*k 2 k 1 self.node[2*k+2] self.node self node 2*k+2 2*k 2 k 2 self self k k x x def get(self, l, r):
        x = self.e
        l += self.size; r += self.size
        a, b = [], []

        while l<r:
            if l&1:
                a += [l-1]; l += 1
            if r&1:
                r -= 1; b += [r-1]
            l >>= 1; r >>= 1

        for i in a+(b[::-1]):
            x = self.op(x, self.node[i])
        return x get x = self.e x self.e self e l += self.size l self.size self size r += self.size r self.size self size a, b = [], [] a [] b [] while l<r:
            if l&1:
                a += [l-1]; l += 1
            if r&1:
                r -= 1; b += [r-1]
            l >>= 1; r >>= 1

         l<r l r if l&1:
                a += [l-1]; l += 1
             l&1 l 1 a += [l-1] a [l-1] l-1 l 1 l += 1 l 1 if r&1:
                r -= 1; b += [r-1]
             r&1 r 1 r -= 1 r 1 b += [r-1] b [r-1] r-1 r 1 l >>= 1 l 1 r >>= 1 r 1 for i in a+(b[::-1]):
            x = self.op(x, self.node[i])
         i a+(b[::-1]) a b[::-1] b ::-1 -1 x = self.op(x, self.node[i]) x self.op(x, self.node[i]) self.op self op x self.node[i] self.node self node i return x x self self l l r r def main():
    N = int(input())
    S = list(input())[:-1]
    trees = {chr(97+i):SegTree(N, e=0, operator_func=or_) for i in range(26)}

    for i, s in enumerate(S):
        trees[s].update(i, 1)

    Q = int(input())
    for _ in range(Q):
        mode, i, v = input().split()
        if mode=="1":
            i = int(i)-1
            trees[S[i]].update(i, 0)
            trees[v].update(i, 1)
            S[i] = v
        else:
            i = int(i)-1
            v = int(v)
            ans = sum(trees[chr(97+j)].get(i, v) for j in range(26))
            print(ans) main N = int(input()) N int(input()) int input() input S = list(input())[:-1] S list(input())[:-1] (input()) list input() input :-1 -1 chr(97+i):SegTree(N, e=0, operator_func=or_) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) chr(97+i) chr 97+i 97 i SegTree(N, e=0, operator_func=or_) SegTree N e=0 e 0 operator_func=or_ operator_func or_ trees = {chr(97+i):SegTree(N, e=0, operator_func=or_) for i in range(26)} trees {chr(97+i):SegTree(N, e=0, operator_func=or_) for i in range(26)} for i, s in enumerate(S):
        trees[s].update(i, 1)

     i s enumerate(S) enumerate S trees[s].update(i, 1) [s].update [s] trees s update i 1 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
        mode, i, v = input().split()
        if mode=="1":
            i = int(i)-1
            trees[S[i]].update(i, 0)
            trees[v].update(i, 1)
            S[i] = v
        else:
            i = int(i)-1
            v = int(v)
            ans = sum(trees[chr(97+j)].get(i, v) for j in range(26))
            print(ans) _ range(Q) range Q mode, i, v = input().split() mode input().split() ().split () input split i v if mode=="1":
            i = int(i)-1
            trees[S[i]].update(i, 0)
            trees[v].update(i, 1)
            S[i] = v
        else:
            i = int(i)-1
            v = int(v)
            ans = sum(trees[chr(97+j)].get(i, v) for j in range(26))
            print(ans) mode=="1" mode "1" i = int(i)-1 i int(i)-1 int(i) int i 1 trees[S[i]].update(i, 0) [S[i]].update [S[i]] trees S[i] S i update i 0 trees[v].update(i, 1) [v].update [v] trees v update i 1 S[i] = v S[i] S i v i = int(i)-1 i int(i)-1 int(i) int i 1 v = int(v) v int(v) int v ans = sum(trees[chr(97+j)].get(i, v) for j in range(26)) ans sum(trees[chr(97+j)].get(i, v) for j in range(26)) sum trees[chr(97+j)].get(i, v) [chr(97+j)].get [chr(97+j)] trees chr(97+j) chr 97+j 97 j get i v print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main input=sys.stdin.readline sys.stdin.readline input class SegTree():
    def __init__(self, N, e=float("inf"), operator_func=min):
        self.e = e
        self.size = N
        self.node = [self.e] * (2*N)
        self.op = operator_func

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size - 1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        x = self.e
        l += self.size; r += self.size
        a, b = [], []

        while l<r:
            if l&1:
                a += [l-1]; l += 1
            if r&1:
                r -= 1; b += [r-1]
            l >>= 1; r >>= 1

        for i in a+(b[::-1]):
            x = self.op(x, self.node[i])
        return x class SegTree():
    def __init__(self, N, e=float("inf"), operator_func=min):
        self.e = e
        self.size = N
        self.node = [self.e] * (2*N)
        self.op = operator_func

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size - 1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        x = self.e
        l += self.size; r += self.size
        a, b = [], []

        while l<r:
            if l&1:
                a += [l-1]; l += 1
            if r&1:
                r -= 1; b += [r-1]
            l >>= 1; r >>= 1

        for i in a+(b[::-1]):
            x = self.op(x, self.node[i])
        return x SegTree def main():
    N = int(input())
    S = list(input())[:-1]
    trees = {chr(97+i):SegTree(N, e=0, operator_func=or_) for i in range(26)}

    for i, s in enumerate(S):
        trees[s].update(i, 1)

    Q = int(input())
    for _ in range(Q):
        mode, i, v = input().split()
        if mode=="1":
            i = int(i)-1
            trees[S[i]].update(i, 0)
            trees[v].update(i, 1)
            S[i] = v
        else:
            i = int(i)-1
            v = int(v)
            ans = sum(trees[chr(97+j)].get(i, v) for j in range(26))
            print(ans) def main():
    N = int(input())
    S = list(input())[:-1]
    trees = {chr(97+i):SegTree(N, e=0, operator_func=or_) for i in range(26)}

    for i, s in enumerate(S):
        trees[s].update(i, 1)

    Q = int(input())
    for _ in range(Q):
        mode, i, v = input().split()
        if mode=="1":
            i = int(i)-1
            trees[S[i]].update(i, 0)
            trees[v].update(i, 1)
            S[i] = v
        else:
            i = int(i)-1
            v = int(v)
            ans = sum(trees[chr(97+j)].get(i, v) for j in range(26))
            print(ans) main
import sys
from operator import or_
input=sys.stdin.readline


class SegTree():
    def __init__(self, N, e=float("inf"), operator_func=min):
        self.e = e
        self.size = N
        self.node = [self.e] * (2*N)
        self.op = operator_func

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size - 1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        x = self.e
        l += self.size; r += self.size
        a, b = [], []

        while l<r:
            if l&1:
                a += [l-1]; l += 1
            if r&1:
                r -= 1; b += [r-1]
            l >>= 1; r >>= 1

        for i in a+(b[::-1]):
            x = self.op(x, self.node[i])
        return x


def main():
    N = int(input())
    S = list(input())[:-1]
    trees = {chr(97+i):SegTree(N, e=0, operator_func=or_) for i in range(26)}

    for i, s in enumerate(S):
        trees[s].update(i, 1)

    Q = int(input())
    for _ in range(Q):
        mode, i, v = input().split()
        if mode=="1":
            i = int(i)-1
            trees[S[i]].update(i, 0)
            trees[v].update(i, 1)
            S[i] = v
        else:
            i = int(i)-1
            v = int(v)
            ans = sum(trees[chr(97+j)].get(i, v) for j in range(26))
            print(ans)


if __name__ == "__main__":
    main()