# E - Simple String Queries

class FenwickTree():
    
    # インデックスは1-start
    # 初期化
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    # private function
    def summation(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    
    # i番目の要素にxを加える（初期値 0）
    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    # i番目の要素 or [i,j]の要素和を取得
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.summation(j) - self.summation(i-1)

N = int(input())
S_raw = input()
S = [0]*(N+1)
trees = [FenwickTree(N) for _ in range(26)]
for i in range(1,N+1):
    s = S_raw[i-1]
    S[i] = s
    k = ord(s)-ord('a')
    trees[k].add(i, 1)

Q = int(input())
for _ in range(Q):
    q,x,y = input().split()
    if q=='1':
        i,c = int(x),y
        s = S[i]
        k = ord(s)-ord('a')
        trees[k].add(i, -1)
        S[i] = c
        k = ord(c)-ord('a')
        trees[k].add(i, 1)
    else:
        l,r = int(x),int(y)
        ans = 0
        for k in range(26):
            ans = ans+1 if trees[k].get(l,r)>0 else ans
        print(ans) class FenwickTree():
    
    # インデックスは1-start
    # 初期化
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    # private function
    def summation(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    
    # i番目の要素にxを加える（初期値 0）
    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    # i番目の要素 or [i,j]の要素和を取得
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.summation(j) - self.summation(i-1) FenwickTree def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    # private function
     __init__ self.n = n self.n self n n self.data = [0]*(n+1) self.data self data [0]*(n+1) [0] 0 n+1 n 1 self.el = [0]*(n+1) self.el self el [0]*(n+1) [0] 0 n+1 n 1 self self n n def summation(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    
    # i番目の要素にxを加える（初期値 0）
     summation s = 0 s 0 while i > 0:
            s += self.data[i]
            i -= i & -i
         i > 0 i 0 s += self.data[i] s self.data[i] self.data self data i i -= i & -i i i & -i i -i i return s s self self i i def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    # i番目の要素 or [i,j]の要素和を取得
     add self.el[i] += x self.el[i] self.el self el i x while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    # i番目の要素 or [i,j]の要素和を取得
     i <= self.n i self.n self n self.data[i] += x self.data[i] self.data self data i x i += i & -i i i & -i i -i i self self i i x x def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.summation(j) - self.summation(i-1) get if j is None:
            return self.el[i]
         j is None j None return self.el[i] self.el[i] self.el self el i return self.summation(j) - self.summation(i-1) self.summation(j) - self.summation(i-1) self.summation(j) self.summation self summation j self.summation(i-1) self.summation self summation i-1 i 1 self self i i j=None j None N = int(input()) N int(input()) int input() input S_raw = input() S_raw input() input S = [0]*(N+1) S [0]*(N+1) [0] 0 N+1 N 1 FenwickTree(N) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) FenwickTree(N) FenwickTree N trees = [FenwickTree(N) for _ in range(26)] trees [FenwickTree(N) for _ in range(26)] for i in range(1,N+1):
    s = S_raw[i-1]
    S[i] = s
    k = ord(s)-ord('a')
    trees[k].add(i, 1) i range(1,N+1) range 1 N+1 N 1 s = S_raw[i-1] s S_raw[i-1] S_raw i-1 i 1 S[i] = s S[i] S i s k = ord(s)-ord('a') k ord(s)-ord('a') ord(s) ord s ord('a') ord 'a' trees[k].add(i, 1) [k].add [k] trees k add i 1 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    q,x,y = input().split()
    if q=='1':
        i,c = int(x),y
        s = S[i]
        k = ord(s)-ord('a')
        trees[k].add(i, -1)
        S[i] = c
        k = ord(c)-ord('a')
        trees[k].add(i, 1)
    else:
        l,r = int(x),int(y)
        ans = 0
        for k in range(26):
            ans = ans+1 if trees[k].get(l,r)>0 else ans
        print(ans) _ range(Q) range Q q,x,y = input().split() q input().split() ().split () input split x y if q=='1':
        i,c = int(x),y
        s = S[i]
        k = ord(s)-ord('a')
        trees[k].add(i, -1)
        S[i] = c
        k = ord(c)-ord('a')
        trees[k].add(i, 1)
    else:
        l,r = int(x),int(y)
        ans = 0
        for k in range(26):
            ans = ans+1 if trees[k].get(l,r)>0 else ans
        print(ans) q=='1' q '1' i,c = int(x),y i int(x) int x c y s = S[i] s S[i] S i k = ord(s)-ord('a') k ord(s)-ord('a') ord(s) ord s ord('a') ord 'a' trees[k].add(i, -1) [k].add [k] trees k add i -1 S[i] = c S[i] S i c k = ord(c)-ord('a') k ord(c)-ord('a') ord(c) ord c ord('a') ord 'a' trees[k].add(i, 1) [k].add [k] trees k add i 1 l,r = int(x),int(y) l int(x) int x r int(y) int y ans = 0 ans 0 for k in range(26):
            ans = ans+1 if trees[k].get(l,r)>0 else ans
         k range(26) range 26 ans = ans+1 if trees[k].get(l,r)>0 else ans ans ans+1 if trees[k].get(l,r)>0 else ans trees[k].get(l,r)>0 trees[k].get(l,r) [k].get [k] trees k get l r 0 ans+1 ans 1 ans print(ans) print ans y = input().split() input().split() y c = int(x),y y c ans = ans+1 if trees[k].get(l,r)>0 else ans ans+1 if trees[k].get(l,r)>0 else ans ans r = int(x),int(y) int(y) r q,x,y = input().split() input().split() q k = ord(s)-ord('a') ord(s)-ord('a') k Q = int(input()) int(input()) Q s = S_raw[i-1] S_raw[i-1] s class FenwickTree():
    
    # インデックスは1-start
    # 初期化
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    # private function
    def summation(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    
    # i番目の要素にxを加える（初期値 0）
    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    # i番目の要素 or [i,j]の要素和を取得
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.summation(j) - self.summation(i-1) class FenwickTree():
    
    # インデックスは1-start
    # 初期化
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    # private function
    def summation(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    
    # i番目の要素にxを加える（初期値 0）
    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    # i番目の要素 or [i,j]の要素和を取得
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.summation(j) - self.summation(i-1) FenwickTree N = int(input()) int(input()) N l,r = int(x),int(y) int(x) l k = ord(c)-ord('a') ord(c)-ord('a') k s = S[i] S[i] s k = ord(s)-ord('a') ord(s)-ord('a') k S_raw = input() input() S_raw S = [0]*(N+1) [0]*(N+1) S x,y = input().split() input().split() x trees = [FenwickTree(N) for _ in range(26)] [FenwickTree(N) for _ in range(26)] trees i,c = int(x),y int(x) i ans = 0 0 ans
# E - Simple String Queries

class FenwickTree():
    
    # インデックスは1-start
    # 初期化
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    # private function
    def summation(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    
    # i番目の要素にxを加える（初期値 0）
    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    # i番目の要素 or [i,j]の要素和を取得
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.summation(j) - self.summation(i-1)

N = int(input())
S_raw = input()
S = [0]*(N+1)
trees = [FenwickTree(N) for _ in range(26)]
for i in range(1,N+1):
    s = S_raw[i-1]
    S[i] = s
    k = ord(s)-ord('a')
    trees[k].add(i, 1)

Q = int(input())
for _ in range(Q):
    q,x,y = input().split()
    if q=='1':
        i,c = int(x),y
        s = S[i]
        k = ord(s)-ord('a')
        trees[k].add(i, -1)
        S[i] = c
        k = ord(c)-ord('a')
        trees[k].add(i, 1)
    else:
        l,r = int(x),int(y)
        ans = 0
        for k in range(26):
            ans = ans+1 if trees[k].get(l,r)>0 else ans
        print(ans)