# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

N = int(input())
S = list(input())
Q = int(input())


alphabet = "abcdefghijklmnopqrstuvwxyz"

bag = { l:[] for l in alphabet}

for i in range(N):
  bag[S[i]].append(i+1)


import bisect

for _ in range(Q):
  t,a,b = input().split()
  a = int(a)
  if int(t) == 1:
    if S[a-1]!=b:
      bag[S[a-1]].remove(a)
      S[a-1] = b
      bisect.insort(bag[b],a)
  else:
    count = 0
    b = int(b)
    for l in alphabet:
      if len(bag[l])>0:
        left = bisect.bisect_left(bag[l],a)
        if left != len(bag[l]):
          if bag[l][left] <= b:
            count += 1
    print(count) 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 = list(input()) S list(input()) list input() input Q = int(input()) Q int(input()) int input() input alphabet = "abcdefghijklmnopqrstuvwxyz" alphabet "abcdefghijklmnopqrstuvwxyz" l:[] for l in alphabet for l in alphabet l alphabet for l in alphabet l [] bag = { l:[] for l in alphabet} bag { l:[] for l in alphabet} for i in range(N):
  bag[S[i]].append(i+1) i range(N) range N bag[S[i]].append(i+1) [S[i]].append [S[i]] bag S[i] S i append i+1 i 1 import bisect bisect for _ in range(Q):
  t,a,b = input().split()
  a = int(a)
  if int(t) == 1:
    if S[a-1]!=b:
      bag[S[a-1]].remove(a)
      S[a-1] = b
      bisect.insort(bag[b],a)
  else:
    count = 0
    b = int(b)
    for l in alphabet:
      if len(bag[l])>0:
        left = bisect.bisect_left(bag[l],a)
        if left != len(bag[l]):
          if bag[l][left] <= b:
            count += 1
    print(count) _ range(Q) range Q t,a,b = input().split() t input().split() ().split () input split a b a = int(a) a int(a) int a if int(t) == 1:
    if S[a-1]!=b:
      bag[S[a-1]].remove(a)
      S[a-1] = b
      bisect.insort(bag[b],a)
  else:
    count = 0
    b = int(b)
    for l in alphabet:
      if len(bag[l])>0:
        left = bisect.bisect_left(bag[l],a)
        if left != len(bag[l]):
          if bag[l][left] <= b:
            count += 1
    print(count) int(t) == 1 int(t) int t 1 if S[a-1]!=b:
      bag[S[a-1]].remove(a)
      S[a-1] = b
      bisect.insort(bag[b],a)
   S[a-1]!=b S[a-1] S a-1 a 1 b bag[S[a-1]].remove(a) [S[a-1]].remove [S[a-1]] bag S[a-1] S a-1 a 1 remove a S[a-1] = b S[a-1] S a-1 a 1 b bisect.insort(bag[b],a) bisect.insort bisect insort bag[b] bag b a count = 0 count 0 b = int(b) b int(b) int b for l in alphabet:
      if len(bag[l])>0:
        left = bisect.bisect_left(bag[l],a)
        if left != len(bag[l]):
          if bag[l][left] <= b:
            count += 1
     l alphabet if len(bag[l])>0:
        left = bisect.bisect_left(bag[l],a)
        if left != len(bag[l]):
          if bag[l][left] <= b:
            count += 1
     len(bag[l])>0 len(bag[l]) len bag[l] bag l 0 left = bisect.bisect_left(bag[l],a) left bisect.bisect_left(bag[l],a) bisect.bisect_left bisect bisect_left bag[l] bag l a if left != len(bag[l]):
          if bag[l][left] <= b:
            count += 1
     left != len(bag[l]) left len(bag[l]) len bag[l] bag l if bag[l][left] <= b:
            count += 1
     bag[l][left] <= b bag[l][left] [l] bag l left b count += 1 count 1 print(count) print count input = sys.stdin.readline sys.stdin.readline input a = int(a) int(a) a t,a,b = input().split() input().split() t Q = int(input()) int(input()) Q b = input().split() input().split() b a,b = input().split() input().split() a left = bisect.bisect_left(bag[l],a) bisect.bisect_left(bag[l],a) left b = int(b) int(b) b N = int(input()) int(input()) N alphabet = "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" alphabet S = list(input()) list(input()) S bag = { l:[] for l in alphabet} { l:[] for l in alphabet} bag count = 0 0 count count += 1 1 count
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

N = int(input())
S = list(input())
Q = int(input())


alphabet = "abcdefghijklmnopqrstuvwxyz"

bag = { l:[] for l in alphabet}

for i in range(N):
  bag[S[i]].append(i+1)


import bisect

for _ in range(Q):
  t,a,b = input().split()
  a = int(a)
  if int(t) == 1:
    if S[a-1]!=b:
      bag[S[a-1]].remove(a)
      S[a-1] = b
      bisect.insort(bag[b],a)
  else:
    count = 0
    b = int(b)
    for l in alphabet:
      if len(bag[l])>0:
        left = bisect.bisect_left(bag[l],a)
        if left != len(bag[l]):
          if bag[l][left] <= b:
            count += 1
    print(count)
