import sys
input = sys.stdin.readline
N = int(input())
S = input().rstrip()
Q = int(input())
qs = [input().split() for i in range(Q)]

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

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)
bits = [BinaryIndexedTree(N) for _ in range(26)]

for i,c in enumerate(S):
    bits[ctoi(c)].add(i,1)

s = list(S)
ans = []
for a,b,c in qs:
    if a=='1':
        x = int(b)-1
        bits[ctoi(c)].add(x,1)
        bits[ctoi(s[x])].add(x,-1)
        s[x] = c
    else:
        b,c = int(b)-1,int(c)
        tmp = 0
        for i in range(26):
            if bits[i].sum(b,c) > 0:
                tmp += 1
        ans.append(tmp)
print(*ans, sep='\n') import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N = int(input()) N int(input()) int input() input S = input().rstrip() S input().rstrip() ().rstrip () input rstrip 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 qs = [input().split() for i in range(Q)] qs [input().split() for i in range(Q)] 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 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) 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 BinaryIndexedTree(N) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BinaryIndexedTree(N) BinaryIndexedTree N bits = [BinaryIndexedTree(N) for _ in range(26)] bits [BinaryIndexedTree(N) for _ in range(26)] for i,c in enumerate(S):
    bits[ctoi(c)].add(i,1) i c enumerate(S) enumerate S bits[ctoi(c)].add(i,1) [ctoi(c)].add [ctoi(c)] bits ctoi(c) ctoi c add i 1 s = list(S) s list(S) list S ans = [] ans [] for a,b,c in qs:
    if a=='1':
        x = int(b)-1
        bits[ctoi(c)].add(x,1)
        bits[ctoi(s[x])].add(x,-1)
        s[x] = c
    else:
        b,c = int(b)-1,int(c)
        tmp = 0
        for i in range(26):
            if bits[i].sum(b,c) > 0:
                tmp += 1
        ans.append(tmp) a b c qs if a=='1':
        x = int(b)-1
        bits[ctoi(c)].add(x,1)
        bits[ctoi(s[x])].add(x,-1)
        s[x] = c
    else:
        b,c = int(b)-1,int(c)
        tmp = 0
        for i in range(26):
            if bits[i].sum(b,c) > 0:
                tmp += 1
        ans.append(tmp) a=='1' a '1' x = int(b)-1 x int(b)-1 int(b) int b 1 bits[ctoi(c)].add(x,1) [ctoi(c)].add [ctoi(c)] bits ctoi(c) ctoi c add x 1 bits[ctoi(s[x])].add(x,-1) [ctoi(s[x])].add [ctoi(s[x])] bits ctoi(s[x]) ctoi s[x] s x add x -1 s[x] = c s[x] s x c b,c = int(b)-1,int(c) b int(b)-1 int(b) int b 1 c int(c) int c tmp = 0 tmp 0 for i in range(26):
            if bits[i].sum(b,c) > 0:
                tmp += 1
         i range(26) range 26 if bits[i].sum(b,c) > 0:
                tmp += 1
         bits[i].sum(b,c) > 0 bits[i].sum(b,c) [i].sum [i] bits i sum b c 0 tmp += 1 tmp 1 ans.append(tmp) ans.append ans append tmp print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' bits = [BinaryIndexedTree(N) for _ in range(26)] [BinaryIndexedTree(N) for _ in range(26)] bits 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) 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) BinaryIndexedTree qs = [input().split() for i in range(Q)] [input().split() for i in range(Q)] qs input = sys.stdin.readline sys.stdin.readline input b,c = int(b)-1,int(c) int(b)-1 b S = input().rstrip() input().rstrip() S tmp = 0 0 tmp tmp += 1 1 tmp N = int(input()) int(input()) N def ctoi(c):
    return ord(c) - ord('a') def ctoi(c):
    return ord(c) - ord('a') ctoi ans = [] [] ans s = list(S) list(S) s Q = int(input()) int(input()) Q x = int(b)-1 int(b)-1 x c = int(b)-1,int(c) int(c) c
import sys
input = sys.stdin.readline
N = int(input())
S = input().rstrip()
Q = int(input())
qs = [input().split() for i in range(Q)]

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

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)
bits = [BinaryIndexedTree(N) for _ in range(26)]

for i,c in enumerate(S):
    bits[ctoi(c)].add(i,1)

s = list(S)
ans = []
for a,b,c in qs:
    if a=='1':
        x = int(b)-1
        bits[ctoi(c)].add(x,1)
        bits[ctoi(s[x])].add(x,-1)
        s[x] = c
    else:
        b,c = int(b)-1,int(c)
        tmp = 0
        for i in range(26):
            if bits[i].sum(b,c) > 0:
                tmp += 1
        ans.append(tmp)
print(*ans, sep='\n')