import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

class BIT:
    def __init__(self, n):
        self.n = n
        self.nums = [0] * (n+1)
        
    def add(self, i, x):
        n, nums = self.n, self.nums
        i += 1
        while i <= n:
            nums[i] += x
            i += i & -i
    
    def sum(self, i):
        nums = self.nums
        s = 0
        i += 1
        while i:
            s += nums[i]
            i -= i & -i
        return s
    
    def search(self, x):
        n, nums = self.n, self.nums
        s, p = 0, 0
        for i in range(n.bit_length(), -1, -1):
            np = p + (1<<i)
            if np <= n and s+nums[np] < x:
                s += nums[np]
                p = np
        return p


N = ri()
S = rs()
Q = ri()
queries = []
for i in range(Q):
	q = rs().split()
	if q[0] == '1':
		q = (int(q[0]), int(q[1])-1, q[2])
	else:
		q = (int(q[0]), int(q[1])-1, int(q[2])-1)
	queries.append(q)

import collections
h = collections.defaultdict(lambda: BIT(N))

S = list(S)
for i, s in enumerate(S):
	h[s].add(i, 1)
for q in queries:
	if q[0] == 1:
		i, c = q[1], q[2]
		h[S[i]].add(i, -1)
		h[c].add(i, 1)
		S[i] = c
	else:
		l, r = q[1], q[2]
		cnt = 0
		for c, bit in h.items():
			if bit.sum(r) - bit.sum(l-1) > 0:
				cnt += 1
		print(cnt) import sys, math sys math input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline rs = lambda: input().strip() rs lambda: input().strip() input().strip() ().strip () input strip ri = lambda: int(input()) ri lambda: int(input()) int(input()) int input() input rl = lambda: list(map(int, input().split())) rl lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 class BIT:
    def __init__(self, n):
        self.n = n
        self.nums = [0] * (n+1)
        
    def add(self, i, x):
        n, nums = self.n, self.nums
        i += 1
        while i <= n:
            nums[i] += x
            i += i & -i
    
    def sum(self, i):
        nums = self.nums
        s = 0
        i += 1
        while i:
            s += nums[i]
            i -= i & -i
        return s
    
    def search(self, x):
        n, nums = self.n, self.nums
        s, p = 0, 0
        for i in range(n.bit_length(), -1, -1):
            np = p + (1<<i)
            if np <= n and s+nums[np] < x:
                s += nums[np]
                p = np
        return p BIT def __init__(self, n):
        self.n = n
        self.nums = [0] * (n+1)
        
     __init__ self.n = n self.n self n n self.nums = [0] * (n+1) self.nums self nums [0] * (n+1) [0] 0 n+1 n 1 self self n n def add(self, i, x):
        n, nums = self.n, self.nums
        i += 1
        while i <= n:
            nums[i] += x
            i += i & -i
    
     add n, nums = self.n, self.nums n self.n self n nums self.nums self nums i += 1 i 1 while i <= n:
            nums[i] += x
            i += i & -i
    
     i <= n i n nums[i] += x nums[i] nums i x i += i & -i i i & -i i -i i self self i i x x def sum(self, i):
        nums = self.nums
        s = 0
        i += 1
        while i:
            s += nums[i]
            i -= i & -i
        return s
    
     sum nums = self.nums nums self.nums self nums s = 0 s 0 i += 1 i 1 while i:
            s += nums[i]
            i -= i & -i
         i s += nums[i] s nums[i] nums i i -= i & -i i i & -i i -i i return s s self self i i def search(self, x):
        n, nums = self.n, self.nums
        s, p = 0, 0
        for i in range(n.bit_length(), -1, -1):
            np = p + (1<<i)
            if np <= n and s+nums[np] < x:
                s += nums[np]
                p = np
        return p search n, nums = self.n, self.nums n self.n self n nums self.nums self nums s, p = 0, 0 s 0 p 0 for i in range(n.bit_length(), -1, -1):
            np = p + (1<<i)
            if np <= n and s+nums[np] < x:
                s += nums[np]
                p = np
         i range(n.bit_length(), -1, -1) range n.bit_length() n.bit_length n bit_length -1 -1 np = p + (1<<i) np p + (1<<i) p 1<<i 1 i if np <= n and s+nums[np] < x:
                s += nums[np]
                p = np
         np <= n and s+nums[np] < x np <= n np n s+nums[np] < x s+nums[np] s nums[np] nums np x s += nums[np] s nums[np] nums np p = np p np return p p self self x x N = ri() N ri() ri S = rs() S rs() rs Q = ri() Q ri() ri queries = [] queries [] for i in range(Q):
	q = rs().split()
	if q[0] == '1':
		q = (int(q[0]), int(q[1])-1, q[2])
	else:
		q = (int(q[0]), int(q[1])-1, int(q[2])-1)
	queries.append(q) i range(Q) range Q q = rs().split() q rs().split() ().split () rs split if q[0] == '1':
		q = (int(q[0]), int(q[1])-1, q[2])
	else:
		q = (int(q[0]), int(q[1])-1, int(q[2])-1)
	 q[0] == '1' q[0] q 0 '1' q = (int(q[0]), int(q[1])-1, q[2]) q (int(q[0]), int(q[1])-1, q[2]) int(q[0]) int q[0] q 0 int(q[1])-1 int(q[1]) int q[1] q 1 1 q[2] q 2 q = (int(q[0]), int(q[1])-1, int(q[2])-1) q (int(q[0]), int(q[1])-1, int(q[2])-1) int(q[0]) int q[0] q 0 int(q[1])-1 int(q[1]) int q[1] q 1 1 int(q[2])-1 int(q[2]) int q[2] q 2 1 queries.append(q) queries.append queries append q import collections collections h = collections.defaultdict(lambda: BIT(N)) h collections.defaultdict(lambda: BIT(N)) collections.defaultdict collections defaultdict lambda: BIT(N) BIT(N) BIT N S = list(S) S list(S) list S for i, s in enumerate(S):
	h[s].add(i, 1) i s enumerate(S) enumerate S h[s].add(i, 1) [s].add [s] h s add i 1 for q in queries:
	if q[0] == 1:
		i, c = q[1], q[2]
		h[S[i]].add(i, -1)
		h[c].add(i, 1)
		S[i] = c
	else:
		l, r = q[1], q[2]
		cnt = 0
		for c, bit in h.items():
			if bit.sum(r) - bit.sum(l-1) > 0:
				cnt += 1
		print(cnt) q queries if q[0] == 1:
		i, c = q[1], q[2]
		h[S[i]].add(i, -1)
		h[c].add(i, 1)
		S[i] = c
	else:
		l, r = q[1], q[2]
		cnt = 0
		for c, bit in h.items():
			if bit.sum(r) - bit.sum(l-1) > 0:
				cnt += 1
		print(cnt) q[0] == 1 q[0] q 0 1 i, c = q[1], q[2] i q[1] q 1 c q[2] q 2 h[S[i]].add(i, -1) [S[i]].add [S[i]] h S[i] S i add i -1 h[c].add(i, 1) [c].add [c] h c add i 1 S[i] = c S[i] S i c l, r = q[1], q[2] l q[1] q 1 r q[2] q 2 cnt = 0 cnt 0 for c, bit in h.items():
			if bit.sum(r) - bit.sum(l-1) > 0:
				cnt += 1
		 c bit h.items() h.items h items if bit.sum(r) - bit.sum(l-1) > 0:
				cnt += 1
		 bit.sum(r) - bit.sum(l-1) > 0 bit.sum(r) - bit.sum(l-1) bit.sum(r) bit.sum bit sum r bit.sum(l-1) bit.sum bit sum l-1 l 1 0 cnt += 1 cnt 1 print(cnt) print cnt h = collections.defaultdict(lambda: BIT(N)) collections.defaultdict(lambda: BIT(N)) h N = ri() ri() N queries = [] [] queries input = sys.stdin.readline sys.stdin.readline input class BIT:
    def __init__(self, n):
        self.n = n
        self.nums = [0] * (n+1)
        
    def add(self, i, x):
        n, nums = self.n, self.nums
        i += 1
        while i <= n:
            nums[i] += x
            i += i & -i
    
    def sum(self, i):
        nums = self.nums
        s = 0
        i += 1
        while i:
            s += nums[i]
            i -= i & -i
        return s
    
    def search(self, x):
        n, nums = self.n, self.nums
        s, p = 0, 0
        for i in range(n.bit_length(), -1, -1):
            np = p + (1<<i)
            if np <= n and s+nums[np] < x:
                s += nums[np]
                p = np
        return p class BIT:
    def __init__(self, n):
        self.n = n
        self.nums = [0] * (n+1)
        
    def add(self, i, x):
        n, nums = self.n, self.nums
        i += 1
        while i <= n:
            nums[i] += x
            i += i & -i
    
    def sum(self, i):
        nums = self.nums
        s = 0
        i += 1
        while i:
            s += nums[i]
            i -= i & -i
        return s
    
    def search(self, x):
        n, nums = self.n, self.nums
        s, p = 0, 0
        for i in range(n.bit_length(), -1, -1):
            np = p + (1<<i)
            if np <= n and s+nums[np] < x:
                s += nums[np]
                p = np
        return p BIT q = rs().split() rs().split() q cnt += 1 1 cnt Q = ri() ri() Q q = (int(q[0]), int(q[1])-1, q[2]) (int(q[0]), int(q[1])-1, q[2]) q c = q[1], q[2] q[2] c mod = 10**9 + 7 10**9 + 7 mod rl = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) rl S = list(S) list(S) S rs = lambda: input().strip() lambda: input().strip() rs i, c = q[1], q[2] q[1] i ri = lambda: int(input()) lambda: int(input()) ri l, r = q[1], q[2] q[1] l S = rs() rs() S r = q[1], q[2] q[2] r cnt = 0 0 cnt q = (int(q[0]), int(q[1])-1, int(q[2])-1) (int(q[0]), int(q[1])-1, int(q[2])-1) q
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

class BIT:
    def __init__(self, n):
        self.n = n
        self.nums = [0] * (n+1)
        
    def add(self, i, x):
        n, nums = self.n, self.nums
        i += 1
        while i <= n:
            nums[i] += x
            i += i & -i
    
    def sum(self, i):
        nums = self.nums
        s = 0
        i += 1
        while i:
            s += nums[i]
            i -= i & -i
        return s
    
    def search(self, x):
        n, nums = self.n, self.nums
        s, p = 0, 0
        for i in range(n.bit_length(), -1, -1):
            np = p + (1<<i)
            if np <= n and s+nums[np] < x:
                s += nums[np]
                p = np
        return p


N = ri()
S = rs()
Q = ri()
queries = []
for i in range(Q):
	q = rs().split()
	if q[0] == '1':
		q = (int(q[0]), int(q[1])-1, q[2])
	else:
		q = (int(q[0]), int(q[1])-1, int(q[2])-1)
	queries.append(q)

import collections
h = collections.defaultdict(lambda: BIT(N))

S = list(S)
for i, s in enumerate(S):
	h[s].add(i, 1)
for q in queries:
	if q[0] == 1:
		i, c = q[1], q[2]
		h[S[i]].add(i, -1)
		h[c].add(i, 1)
		S[i] = c
	else:
		l, r = q[1], q[2]
		cnt = 0
		for c, bit in h.items():
			if bit.sum(r) - bit.sum(l-1) > 0:
				cnt += 1
		print(cnt)
