import sys
input = sys.stdin.readline

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s

N = int(input())
S = list(input()[:-1])
bits = [BIT(N) for _ in range(26)]

for i in range(N):
    j = ord(S[i])-ord('a')
    bits[j].add(i, 1)

Q = int(input())

for _ in range(Q):
    q = input().split()
    
    if q[0]=='1':
        i, c = int(q[1])-1, q[2]
        j = ord(S[i])-ord('a')
        bits[j].add(i, -1)
        k = ord(c)-ord('a')
        bits[k].add(i, 1)
        S[i] = c
    else:
        l, r = int(q[1])-1, int(q[2])-1
        ans = 0
        
        for i in range(26):
            if bits[i].acc(r+1)-bits[i].acc(l)>0:
                ans += 1
        
        print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s BIT def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
     __init__ self.n = n self.n self n n self.bit = [0]*(n+1) self.bit self bit [0]*(n+1) [0] 0 n+1 n 1 self self n n def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

     add i += 1 i 1 while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

     i<=self.n i self.n self n self.bit[i] += x self.bit[i] self.bit self bit i x i += i&(-i) i i&(-i) i -i i self self i i x x def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s acc s = 0 s 0 while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
         i>0 i 0 s += self.bit[i] s self.bit[i] self.bit self bit i i -= i&(-i) i i&(-i) i -i i return s s self self i i N = int(input()) N int(input()) int input() input S = list(input()[:-1]) S list(input()[:-1]) list input()[:-1] () input :-1 -1 BIT(N) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BIT(N) BIT N bits = [BIT(N) for _ in range(26)] bits [BIT(N) for _ in range(26)] for i in range(N):
    j = ord(S[i])-ord('a')
    bits[j].add(i, 1) i range(N) range N j = ord(S[i])-ord('a') j ord(S[i])-ord('a') ord(S[i]) ord S[i] S i ord('a') ord 'a' bits[j].add(i, 1) [j].add [j] bits j add i 1 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    q = input().split()
    
    if q[0]=='1':
        i, c = int(q[1])-1, q[2]
        j = ord(S[i])-ord('a')
        bits[j].add(i, -1)
        k = ord(c)-ord('a')
        bits[k].add(i, 1)
        S[i] = c
    else:
        l, r = int(q[1])-1, int(q[2])-1
        ans = 0
        
        for i in range(26):
            if bits[i].acc(r+1)-bits[i].acc(l)>0:
                ans += 1
        
        print(ans) _ range(Q) range Q q = input().split() q input().split() ().split () input split if q[0]=='1':
        i, c = int(q[1])-1, q[2]
        j = ord(S[i])-ord('a')
        bits[j].add(i, -1)
        k = ord(c)-ord('a')
        bits[k].add(i, 1)
        S[i] = c
    else:
        l, r = int(q[1])-1, int(q[2])-1
        ans = 0
        
        for i in range(26):
            if bits[i].acc(r+1)-bits[i].acc(l)>0:
                ans += 1
        
        print(ans) q[0]=='1' q[0] q 0 '1' i, c = int(q[1])-1, q[2] i int(q[1])-1 int(q[1]) int q[1] q 1 1 c q[2] q 2 j = ord(S[i])-ord('a') j ord(S[i])-ord('a') ord(S[i]) ord S[i] S i ord('a') ord 'a' bits[j].add(i, -1) [j].add [j] bits j add i -1 k = ord(c)-ord('a') k ord(c)-ord('a') ord(c) ord c ord('a') ord 'a' bits[k].add(i, 1) [k].add [k] bits k add i 1 S[i] = c S[i] S i c l, r = int(q[1])-1, int(q[2])-1 l int(q[1])-1 int(q[1]) int q[1] q 1 1 r int(q[2])-1 int(q[2]) int q[2] q 2 1 ans = 0 ans 0 for i in range(26):
            if bits[i].acc(r+1)-bits[i].acc(l)>0:
                ans += 1
        
         i range(26) range 26 if bits[i].acc(r+1)-bits[i].acc(l)>0:
                ans += 1
        
         bits[i].acc(r+1)-bits[i].acc(l)>0 bits[i].acc(r+1)-bits[i].acc(l) bits[i].acc(r+1) [i].acc [i] bits i acc r+1 r 1 bits[i].acc(l) [i].acc [i] bits i acc l 0 ans += 1 ans 1 print(ans) print ans ans += 1 1 ans j = ord(S[i])-ord('a') ord(S[i])-ord('a') j bits = [BIT(N) for _ in range(26)] [BIT(N) for _ in range(26)] bits c = int(q[1])-1, q[2] q[2] c input = sys.stdin.readline sys.stdin.readline input q = input().split() input().split() q l, r = int(q[1])-1, int(q[2])-1 int(q[1])-1 l class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s BIT N = int(input()) int(input()) N S = list(input()[:-1]) list(input()[:-1]) S ans = 0 0 ans j = ord(S[i])-ord('a') ord(S[i])-ord('a') j k = ord(c)-ord('a') ord(c)-ord('a') k Q = int(input()) int(input()) Q r = int(q[1])-1, int(q[2])-1 int(q[2])-1 r i, c = int(q[1])-1, q[2] int(q[1])-1 i
import sys
input = sys.stdin.readline

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s

N = int(input())
S = list(input()[:-1])
bits = [BIT(N) for _ in range(26)]

for i in range(N):
    j = ord(S[i])-ord('a')
    bits[j].add(i, 1)

Q = int(input())

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