# simpleバージョン
class BinaryIndexedTree:
    def __init__(self,size):
        self.N = size
        self.bit = [0]*(size+1)
    def add(self,x,w): # 0-indexed
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
    def _sum(self,x): # 1-indexed
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
        return ret
    def sum(self,l,r): # [l,r)
        return self._sum(r) - self._sum(l)
    def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.N)]
        return str(arr)


class BIT:
    """ 区間加算BIT(区間加算・区間合計取得) """
 
    def __init__(self, N):
        # 添字0が使えないので、内部的には全て1-indexedとして扱う
        N += 1
        self.N = N
        self.data0 = [0] * N
        self.data1 = [0] * N
 
    def _add(self, data, k, x):
        k += 1
        while k < self.N:
            data[k] += x
            k += k & -k
 
    def _get(self, data, k):
        k += 1
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s
 
    def add(self, l, r, x):
        """ 区間[l,r)に値xを追加 """
 
        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)
 
    def query(self, l, r):
        """ 区間[l,r)の和を取得 """
 
        return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
             - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1)

def ctoi(c):
    return ord(c) - ord('a')

def main():
    N = int(input())
    S = input()
    Q = int(input())
    query = [input().split() for i in range(Q)]
    bits = [BIT(N) for i in range(26)]
    s = []
    for i, c in enumerate(S):
        bits[ctoi(c)].add(i,i+1,1)
        s.append(c)

    for a, b, c in query:
        if a == '1':
            i = int(b) - 1
            bits[ctoi(s[i])].add(i,i+1,-1)
            bits[ctoi(c)].add(i,i+1,1)
            s[i] = c
        else:
            l = int(b) - 1
            r = int(c)
            a = 0
            for i in range(26):
                if bits[i].query(l,r):
                    a += 1
            print(a)




if __name__ == "__main__":
    main() class BinaryIndexedTree:
    def __init__(self,size):
        self.N = size
        self.bit = [0]*(size+1)
    def add(self,x,w): # 0-indexed
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
    def _sum(self,x): # 1-indexed
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
        return ret
    def sum(self,l,r): # [l,r)
        return self._sum(r) - self._sum(l)
    def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.N)]
        return str(arr) BinaryIndexedTree def __init__(self,size):
        self.N = size
        self.bit = [0]*(size+1)
     __init__ self.N = size self.N self N size self.bit = [0]*(size+1) self.bit self bit [0]*(size+1) [0] 0 size+1 size 1 self self size size def add(self,x,w): # 0-indexed
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
     add x += 1 x 1 while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
     x <= self.N x self.N self N self.bit[x] += w self.bit[x] self.bit self bit x w x += (x & -x) x x & -x x -x x self self x x w w def _sum(self,x): # 1-indexed
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
        return ret
     _sum ret = 0 ret 0 while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
         x > 0 x 0 ret += self.bit[x] ret self.bit[x] self.bit self bit x x -= (x & -x) x x & -x x -x x return ret ret self self x x def sum(self,l,r): # [l,r)
        return self._sum(r) - self._sum(l)
     sum return self._sum(r) - self._sum(l) self._sum(r) - self._sum(l) self._sum(r) self._sum self _sum r self._sum(l) self._sum self _sum l self self l l r r def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.N)]
        return str(arr) __str__ self.sum(i,i+1) for i in range(self.N) for i in range(self.N) i range(self.N) range self.N self N for i in range(self.N) self.sum(i,i+1) self.sum self sum i i+1 i 1 arr = [self.sum(i,i+1) for i in range(self.N)] arr [self.sum(i,i+1) for i in range(self.N)] return str(arr) str(arr) str arr self self class BIT:
    """ 区間加算BIT(区間加算・区間合計取得) """
 
    def __init__(self, N):
        # 添字0が使えないので、内部的には全て1-indexedとして扱う
        N += 1
        self.N = N
        self.data0 = [0] * N
        self.data1 = [0] * N
 
    def _add(self, data, k, x):
        k += 1
        while k < self.N:
            data[k] += x
            k += k & -k
 
    def _get(self, data, k):
        k += 1
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s
 
    def add(self, l, r, x):
        """ 区間[l,r)に値xを追加 """
 
        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)
 
    def query(self, l, r):
        """ 区間[l,r)の和を取得 """
 
        return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
             - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1) BIT """ 区間加算BIT(区間加算・区間合計取得) """ def __init__(self, N):
        # 添字0が使えないので、内部的には全て1-indexedとして扱う
        N += 1
        self.N = N
        self.data0 = [0] * N
        self.data1 = [0] * N
 
     __init__ N += 1 N 1 self.N = N self.N self N N self.data0 = [0] * N self.data0 self data0 [0] * N [0] 0 N self.data1 = [0] * N self.data1 self data1 [0] * N [0] 0 N self self N N def _add(self, data, k, x):
        k += 1
        while k < self.N:
            data[k] += x
            k += k & -k
 
     _add k += 1 k 1 while k < self.N:
            data[k] += x
            k += k & -k
 
     k < self.N k self.N self N data[k] += x data[k] data k x k += k & -k k k & -k k -k k self self data data k k x x def _get(self, data, k):
        k += 1
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s
 
     _get k += 1 k 1 s = 0 s 0 while k:
            s += data[k]
            k -= k & -k
         k s += data[k] s data[k] data k k -= k & -k k k & -k k -k k return s s self self data data k k def add(self, l, r, x):
        """ 区間[l,r)に値xを追加 """
 
        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)
 
     add """ 区間[l,r)に値xを追加 """ self._add(self.data0, l, -x*(l-1)) self._add self _add self.data0 self data0 l -x*(l-1) -x x l-1 l 1 self._add(self.data0, r, x*(r-1)) self._add self _add self.data0 self data0 r x*(r-1) x r-1 r 1 self._add(self.data1, l, x) self._add self _add self.data1 self data1 l x self._add(self.data1, r, -x) self._add self _add self.data1 self data1 r -x x self self l l r r x x def query(self, l, r):
        """ 区間[l,r)の和を取得 """
 
        return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
             - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1) query """ 区間[l,r)の和を取得 """ return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
             - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1) self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
             - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1) self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
             - self._get(self.data1, l-1) * (l-1) self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) self._get(self.data1, r-1) * (r-1) self._get(self.data1, r-1) self._get self _get self.data1 self data1 r-1 r 1 r-1 r 1 self._get(self.data0, r-1) self._get self _get self.data0 self data0 r-1 r 1 self._get(self.data1, l-1) * (l-1) self._get(self.data1, l-1) self._get self _get self.data1 self data1 l-1 l 1 l-1 l 1 self._get(self.data0, l-1) self._get self _get self.data0 self data0 l-1 l 1 self self l l r r def ctoi(c):
    return ord(c) - ord('a') ctoi return ord(c) - ord('a') ord(c) - ord('a') ord(c) ord c ord('a') ord 'a' c c def main():
    N = int(input())
    S = input()
    Q = int(input())
    query = [input().split() for i in range(Q)]
    bits = [BIT(N) for i in range(26)]
    s = []
    for i, c in enumerate(S):
        bits[ctoi(c)].add(i,i+1,1)
        s.append(c)

    for a, b, c in query:
        if a == '1':
            i = int(b) - 1
            bits[ctoi(s[i])].add(i,i+1,-1)
            bits[ctoi(c)].add(i,i+1,1)
            s[i] = c
        else:
            l = int(b) - 1
            r = int(c)
            a = 0
            for i in range(26):
                if bits[i].query(l,r):
                    a += 1
            print(a) main N = int(input()) N int(input()) int input() input S = input() S input() input Q = int(input()) Q int(input()) int input() input input().split() for i in range(Q) for i in range(Q) i range(Q) range Q for i in range(Q) input().split() ().split () input split query = [input().split() for i in range(Q)] query [input().split() for i in range(Q)] BIT(N) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) BIT(N) BIT N bits = [BIT(N) for i in range(26)] bits [BIT(N) for i in range(26)] s = [] s [] for i, c in enumerate(S):
        bits[ctoi(c)].add(i,i+1,1)
        s.append(c)

     i c enumerate(S) enumerate S bits[ctoi(c)].add(i,i+1,1) [ctoi(c)].add [ctoi(c)] bits ctoi(c) ctoi c add i i+1 i 1 1 s.append(c) s.append s append c for a, b, c in query:
        if a == '1':
            i = int(b) - 1
            bits[ctoi(s[i])].add(i,i+1,-1)
            bits[ctoi(c)].add(i,i+1,1)
            s[i] = c
        else:
            l = int(b) - 1
            r = int(c)
            a = 0
            for i in range(26):
                if bits[i].query(l,r):
                    a += 1
            print(a) a b c query if a == '1':
            i = int(b) - 1
            bits[ctoi(s[i])].add(i,i+1,-1)
            bits[ctoi(c)].add(i,i+1,1)
            s[i] = c
        else:
            l = int(b) - 1
            r = int(c)
            a = 0
            for i in range(26):
                if bits[i].query(l,r):
                    a += 1
            print(a) a == '1' a '1' i = int(b) - 1 i int(b) - 1 int(b) int b 1 bits[ctoi(s[i])].add(i,i+1,-1) [ctoi(s[i])].add [ctoi(s[i])] bits ctoi(s[i]) ctoi s[i] s i add i i+1 i 1 -1 bits[ctoi(c)].add(i,i+1,1) [ctoi(c)].add [ctoi(c)] bits ctoi(c) ctoi c add i i+1 i 1 1 s[i] = c s[i] s i c l = int(b) - 1 l int(b) - 1 int(b) int b 1 r = int(c) r int(c) int c a = 0 a 0 for i in range(26):
                if bits[i].query(l,r):
                    a += 1
             i range(26) range 26 if bits[i].query(l,r):
                    a += 1
             bits[i].query(l,r) [i].query [i] bits i query l r a += 1 a 1 print(a) print a if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main class BinaryIndexedTree:
    def __init__(self,size):
        self.N = size
        self.bit = [0]*(size+1)
    def add(self,x,w): # 0-indexed
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
    def _sum(self,x): # 1-indexed
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
        return ret
    def sum(self,l,r): # [l,r)
        return self._sum(r) - self._sum(l)
    def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.N)]
        return str(arr) class BinaryIndexedTree:
    def __init__(self,size):
        self.N = size
        self.bit = [0]*(size+1)
    def add(self,x,w): # 0-indexed
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
    def _sum(self,x): # 1-indexed
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
        return ret
    def sum(self,l,r): # [l,r)
        return self._sum(r) - self._sum(l)
    def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.N)]
        return str(arr) BinaryIndexedTree class BIT:
    """ 区間加算BIT(区間加算・区間合計取得) """
 
    def __init__(self, N):
        # 添字0が使えないので、内部的には全て1-indexedとして扱う
        N += 1
        self.N = N
        self.data0 = [0] * N
        self.data1 = [0] * N
 
    def _add(self, data, k, x):
        k += 1
        while k < self.N:
            data[k] += x
            k += k & -k
 
    def _get(self, data, k):
        k += 1
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s
 
    def add(self, l, r, x):
        """ 区間[l,r)に値xを追加 """
 
        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)
 
    def query(self, l, r):
        """ 区間[l,r)の和を取得 """
 
        return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
             - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1) class BIT:
    """ 区間加算BIT(区間加算・区間合計取得) """
 
    def __init__(self, N):
        # 添字0が使えないので、内部的には全て1-indexedとして扱う
        N += 1
        self.N = N
        self.data0 = [0] * N
        self.data1 = [0] * N
 
    def _add(self, data, k, x):
        k += 1
        while k < self.N:
            data[k] += x
            k += k & -k
 
    def _get(self, data, k):
        k += 1
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s
 
    def add(self, l, r, x):
        """ 区間[l,r)に値xを追加 """
 
        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)
 
    def query(self, l, r):
        """ 区間[l,r)の和を取得 """
 
        return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
             - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1) BIT def main():
    N = int(input())
    S = input()
    Q = int(input())
    query = [input().split() for i in range(Q)]
    bits = [BIT(N) for i in range(26)]
    s = []
    for i, c in enumerate(S):
        bits[ctoi(c)].add(i,i+1,1)
        s.append(c)

    for a, b, c in query:
        if a == '1':
            i = int(b) - 1
            bits[ctoi(s[i])].add(i,i+1,-1)
            bits[ctoi(c)].add(i,i+1,1)
            s[i] = c
        else:
            l = int(b) - 1
            r = int(c)
            a = 0
            for i in range(26):
                if bits[i].query(l,r):
                    a += 1
            print(a) def main():
    N = int(input())
    S = input()
    Q = int(input())
    query = [input().split() for i in range(Q)]
    bits = [BIT(N) for i in range(26)]
    s = []
    for i, c in enumerate(S):
        bits[ctoi(c)].add(i,i+1,1)
        s.append(c)

    for a, b, c in query:
        if a == '1':
            i = int(b) - 1
            bits[ctoi(s[i])].add(i,i+1,-1)
            bits[ctoi(c)].add(i,i+1,1)
            s[i] = c
        else:
            l = int(b) - 1
            r = int(c)
            a = 0
            for i in range(26):
                if bits[i].query(l,r):
                    a += 1
            print(a) main def ctoi(c):
    return ord(c) - ord('a') def ctoi(c):
    return ord(c) - ord('a') ctoi
# simpleバージョン
class BinaryIndexedTree:
    def __init__(self,size):
        self.N = size
        self.bit = [0]*(size+1)
    def add(self,x,w): # 0-indexed
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
    def _sum(self,x): # 1-indexed
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
        return ret
    def sum(self,l,r): # [l,r)
        return self._sum(r) - self._sum(l)
    def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.N)]
        return str(arr)


class BIT:
    """ 区間加算BIT(区間加算・区間合計取得) """
 
    def __init__(self, N):
        # 添字0が使えないので、内部的には全て1-indexedとして扱う
        N += 1
        self.N = N
        self.data0 = [0] * N
        self.data1 = [0] * N
 
    def _add(self, data, k, x):
        k += 1
        while k < self.N:
            data[k] += x
            k += k & -k
 
    def _get(self, data, k):
        k += 1
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s
 
    def add(self, l, r, x):
        """ 区間[l,r)に値xを追加 """
 
        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)
 
    def query(self, l, r):
        """ 区間[l,r)の和を取得 """
 
        return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
             - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1)

def ctoi(c):
    return ord(c) - ord('a')

def main():
    N = int(input())
    S = input()
    Q = int(input())
    query = [input().split() for i in range(Q)]
    bits = [BIT(N) for i in range(26)]
    s = []
    for i, c in enumerate(S):
        bits[ctoi(c)].add(i,i+1,1)
        s.append(c)

    for a, b, c in query:
        if a == '1':
            i = int(b) - 1
            bits[ctoi(s[i])].add(i,i+1,-1)
            bits[ctoi(c)].add(i,i+1,1)
            s[i] = c
        else:
            l = int(b) - 1
            r = int(c)
            a = 0
            for i in range(26):
                if bits[i].query(l,r):
                    a += 1
            print(a)




if __name__ == "__main__":
    main()