class segt: def __init__(self, n, calc): self.num = 2 ** (n - 1).bit_length() self.data = [[0]*53 for _ in range(2*self.num)] self.calc = calc def update(self, idx, x): idx += self.num - 1 self.data[idx] = [0] * 53 self.data[idx][x] = 1 while idx > 0: idx = (idx - 1) >> 1 self.data[idx] = self.calc(self.data[2*idx+1][:], self.data[2*idx+2][:])[:] def renew(self, idx, x): self.update(idx, self.calc(self.get(idx), x)) def prod(self, left, right): l = left + self.num r = right + self.num res_l = [0] * 53 res_r = [0] * 53 while l < r: if l % 2: res_l = self.calc(res_l[:], self.data[l-1][:])[:] l += 1 if r % 2: r -= 1 res_r = self.calc(self.data[r-1][:], res_r[:])[:] l >>= 1 r >>= 1 return self.calc(res_l, res_r) def get(self, idx): return self.data[idx+self.num-1] def func(x, y): res = [x[i] + y[i] for i in range(53)] s = sum(y[:26]) for i in range(26): res[i+26] += x[i] * (s - y[i]) for i in range(26): res[52] += x[i] * (x[i] - 1) // 2 * (s - y[i]) res[52] += x[i] * y[i+26] return res n = int(input()) s = list(map(lambda x: ord(x)-65, input())) st = segt(n, func) for i in range(n): st.update(i, s[i]) for _ in range(int(input())): t, x, y = map(str, input().split()) if t == "1": x = int(x) - 1 y = ord(y) - 65 st.update(x, y) else: l = int(x) - 1 r = int(y) print(st.prod(l, r)[52])