n = int(input())
S = list(input())
q = int(input())

import sys
input = sys.stdin.readline

alp = "abcdefghijklmnopqrstuvwxyz"
appr = {a:[] for a in alp}

import bisect

for i, a in enumerate(S):
  appr[a].append(i+1)
#print(appr)
for i in range(q):
  inputs = input().split()
  if inputs[0] == '1':
    c = int(inputs[1])
    a = inputs[2]
    if S[c-1]==a:
      continue
    else:
      old = S[c-1]
      S[c-1] = a
      del_idx = bisect.bisect_left(appr[old], c)
      del appr[old][del_idx]
      in_idx = bisect.bisect_left(appr[a], c)
      appr[a].insert(in_idx, c)
  else:
    l, r = map(int, inputs[1:])
    res = 0
    for a in appr:
      l_idx = bisect.bisect_left(appr[a], l)
      if l_idx<len(appr[a]):
        if appr[a][l_idx]<=r:
          res += 1
    print(res)
    
#print(appr) n = int(input()) n int(input()) int input() input S = list(input()) S list(input()) list input() input q = int(input()) q int(input()) int input() input import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline alp = "abcdefghijklmnopqrstuvwxyz" alp "abcdefghijklmnopqrstuvwxyz" a:[] for a in alp for a in alp a alp for a in alp a [] appr = {a:[] for a in alp} appr {a:[] for a in alp} import bisect bisect for i, a in enumerate(S):
  appr[a].append(i+1)
#print(appr) i a enumerate(S) enumerate S appr[a].append(i+1) [a].append [a] appr a append i+1 i 1 for i in range(q):
  inputs = input().split()
  if inputs[0] == '1':
    c = int(inputs[1])
    a = inputs[2]
    if S[c-1]==a:
      continue
    else:
      old = S[c-1]
      S[c-1] = a
      del_idx = bisect.bisect_left(appr[old], c)
      del appr[old][del_idx]
      in_idx = bisect.bisect_left(appr[a], c)
      appr[a].insert(in_idx, c)
  else:
    l, r = map(int, inputs[1:])
    res = 0
    for a in appr:
      l_idx = bisect.bisect_left(appr[a], l)
      if l_idx<len(appr[a]):
        if appr[a][l_idx]<=r:
          res += 1
    print(res)
    
#print(appr) i range(q) range q inputs = input().split() inputs input().split() ().split () input split if inputs[0] == '1':
    c = int(inputs[1])
    a = inputs[2]
    if S[c-1]==a:
      continue
    else:
      old = S[c-1]
      S[c-1] = a
      del_idx = bisect.bisect_left(appr[old], c)
      del appr[old][del_idx]
      in_idx = bisect.bisect_left(appr[a], c)
      appr[a].insert(in_idx, c)
  else:
    l, r = map(int, inputs[1:])
    res = 0
    for a in appr:
      l_idx = bisect.bisect_left(appr[a], l)
      if l_idx<len(appr[a]):
        if appr[a][l_idx]<=r:
          res += 1
    print(res)
    
#print(appr) inputs[0] == '1' inputs[0] inputs 0 '1' c = int(inputs[1]) c int(inputs[1]) int inputs[1] inputs 1 a = inputs[2] a inputs[2] inputs 2 if S[c-1]==a:
      continue
    else:
      old = S[c-1]
      S[c-1] = a
      del_idx = bisect.bisect_left(appr[old], c)
      del appr[old][del_idx]
      in_idx = bisect.bisect_left(appr[a], c)
      appr[a].insert(in_idx, c)
   S[c-1]==a S[c-1] S c-1 c 1 a continue old = S[c-1] old S[c-1] S c-1 c 1 S[c-1] = a S[c-1] S c-1 c 1 a del_idx = bisect.bisect_left(appr[old], c) del_idx bisect.bisect_left(appr[old], c) bisect.bisect_left bisect bisect_left appr[old] appr old c del appr[old][del_idx] appr[old][del_idx] [old] appr old del_idx in_idx = bisect.bisect_left(appr[a], c) in_idx bisect.bisect_left(appr[a], c) bisect.bisect_left bisect bisect_left appr[a] appr a c appr[a].insert(in_idx, c) [a].insert [a] appr a insert in_idx c l, r = map(int, inputs[1:]) l map(int, inputs[1:]) map int inputs[1:] inputs 1: 1 r res = 0 res 0 for a in appr:
      l_idx = bisect.bisect_left(appr[a], l)
      if l_idx<len(appr[a]):
        if appr[a][l_idx]<=r:
          res += 1
     a appr l_idx = bisect.bisect_left(appr[a], l) l_idx bisect.bisect_left(appr[a], l) bisect.bisect_left bisect bisect_left appr[a] appr a l if l_idx<len(appr[a]):
        if appr[a][l_idx]<=r:
          res += 1
     l_idx<len(appr[a]) l_idx len(appr[a]) len appr[a] appr a if appr[a][l_idx]<=r:
          res += 1
     appr[a][l_idx]<=r appr[a][l_idx] [a] appr a l_idx r res += 1 res 1 print(res) print res res += 1 1 res r = map(int, inputs[1:]) map(int, inputs[1:]) r input = sys.stdin.readline sys.stdin.readline input c = int(inputs[1]) int(inputs[1]) c in_idx = bisect.bisect_left(appr[a], c) bisect.bisect_left(appr[a], c) in_idx S = list(input()) list(input()) S l_idx = bisect.bisect_left(appr[a], l) bisect.bisect_left(appr[a], l) l_idx n = int(input()) int(input()) n alp = "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" alp appr = {a:[] for a in alp} {a:[] for a in alp} appr l, r = map(int, inputs[1:]) map(int, inputs[1:]) l q = int(input()) int(input()) q inputs = input().split() input().split() inputs old = S[c-1] S[c-1] old del_idx = bisect.bisect_left(appr[old], c) bisect.bisect_left(appr[old], c) del_idx a = inputs[2] inputs[2] a res = 0 0 res
n = int(input())
S = list(input())
q = int(input())

import sys
input = sys.stdin.readline

alp = "abcdefghijklmnopqrstuvwxyz"
appr = {a:[] for a in alp}

import bisect

for i, a in enumerate(S):
  appr[a].append(i+1)
#print(appr)
for i in range(q):
  inputs = input().split()
  if inputs[0] == '1':
    c = int(inputs[1])
    a = inputs[2]
    if S[c-1]==a:
      continue
    else:
      old = S[c-1]
      S[c-1] = a
      del_idx = bisect.bisect_left(appr[old], c)
      del appr[old][del_idx]
      in_idx = bisect.bisect_left(appr[a], c)
      appr[a].insert(in_idx, c)
  else:
    l, r = map(int, inputs[1:])
    res = 0
    for a in appr:
      l_idx = bisect.bisect_left(appr[a], l)
      if l_idx<len(appr[a]):
        if appr[a][l_idx]<=r:
          res += 1
    print(res)
    
#print(appr)