class BIT:
  def __init__(self,n):
    self.s = [0]*(n+1)
    self.n = n
  
  def add(self,val,idx):
    while idx < self.n+1:
      self.s[idx] = self.s[idx] + val
      idx += idx&(-idx)
    return
  
  def get(self,idx):
    res = 0
    while idx > 0:
      res = res + self.s[idx]
      idx -= idx&(-idx)
    return res
 
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
 
n = int(input())
S = [ord(s) - ord('a') for s in input()[:-1]]
 
bits = [BIT(n) for i in range(26)]
 
for i,s in enumerate(S):
  bits[s].add(1,i+1)
 
Q = int(input())
ans = []
for _ in range(Q):  
  flag,x,y = input().split()

  if flag == "1":
    i = int(x)
    c = ord(y) - ord('a')
    bits[S[i-1]].add(-1,i)
    bits[c].add(1,i)
    S[i-1] = c
  else:
    l = int(x)
    r = int(y)
    res = 0
    for i in range(26):
      res += (bits[i].get(r) > bits[i].get(l-1))
    ans.append(str(res))

print("\n".join(ans)) class BIT:
  def __init__(self,n):
    self.s = [0]*(n+1)
    self.n = n
  
  def add(self,val,idx):
    while idx < self.n+1:
      self.s[idx] = self.s[idx] + val
      idx += idx&(-idx)
    return
  
  def get(self,idx):
    res = 0
    while idx > 0:
      res = res + self.s[idx]
      idx -= idx&(-idx)
    return res
  BIT def __init__(self,n):
    self.s = [0]*(n+1)
    self.n = n
  
   __init__ self.s = [0]*(n+1) self.s self s [0]*(n+1) [0] 0 n+1 n 1 self.n = n self.n self n n self self n n def add(self,val,idx):
    while idx < self.n+1:
      self.s[idx] = self.s[idx] + val
      idx += idx&(-idx)
    return
  
   add while idx < self.n+1:
      self.s[idx] = self.s[idx] + val
      idx += idx&(-idx)
     idx < self.n+1 idx self.n+1 self.n self n 1 self.s[idx] = self.s[idx] + val self.s[idx] self.s self s idx self.s[idx] + val self.s[idx] self.s self s idx val idx += idx&(-idx) idx idx&(-idx) idx -idx idx return self self val val idx idx def get(self,idx):
    res = 0
    while idx > 0:
      res = res + self.s[idx]
      idx -= idx&(-idx)
    return res
  get res = 0 res 0 while idx > 0:
      res = res + self.s[idx]
      idx -= idx&(-idx)
     idx > 0 idx 0 res = res + self.s[idx] res res + self.s[idx] res self.s[idx] self.s self s idx idx -= idx&(-idx) idx idx&(-idx) idx -idx idx return res res self self idx idx import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n = int(input()) n int(input()) int input() input ord(s) - ord('a') for s in input()[:-1] for s in input()[:-1] s input()[:-1] () input :-1 -1 for s in input()[:-1] ord(s) - ord('a') ord(s) ord s ord('a') ord 'a' S = [ord(s) - ord('a') for s in input()[:-1]] S [ord(s) - ord('a') for s in input()[:-1]] BIT(n) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) BIT(n) BIT n bits = [BIT(n) for i in range(26)] bits [BIT(n) for i in range(26)] for i,s in enumerate(S):
  bits[s].add(1,i+1)
  i s enumerate(S) enumerate S bits[s].add(1,i+1) [s].add [s] bits s add 1 i+1 i 1 Q = int(input()) Q int(input()) int input() input ans = [] ans [] for _ in range(Q):  
  flag,x,y = input().split()

  if flag == "1":
    i = int(x)
    c = ord(y) - ord('a')
    bits[S[i-1]].add(-1,i)
    bits[c].add(1,i)
    S[i-1] = c
  else:
    l = int(x)
    r = int(y)
    res = 0
    for i in range(26):
      res += (bits[i].get(r) > bits[i].get(l-1))
    ans.append(str(res)) _ range(Q) range Q flag,x,y = input().split() flag input().split() ().split () input split x y if flag == "1":
    i = int(x)
    c = ord(y) - ord('a')
    bits[S[i-1]].add(-1,i)
    bits[c].add(1,i)
    S[i-1] = c
  else:
    l = int(x)
    r = int(y)
    res = 0
    for i in range(26):
      res += (bits[i].get(r) > bits[i].get(l-1))
    ans.append(str(res)) flag == "1" flag "1" i = int(x) i int(x) int x c = ord(y) - ord('a') c ord(y) - ord('a') ord(y) ord y ord('a') ord 'a' bits[S[i-1]].add(-1,i) [S[i-1]].add [S[i-1]] bits S[i-1] S i-1 i 1 add -1 i bits[c].add(1,i) [c].add [c] bits c add 1 i S[i-1] = c S[i-1] S i-1 i 1 c l = int(x) l int(x) int x r = int(y) r int(y) int y res = 0 res 0 for i in range(26):
      res += (bits[i].get(r) > bits[i].get(l-1))
     i range(26) range 26 res += (bits[i].get(r) > bits[i].get(l-1)) res bits[i].get(r) > bits[i].get(l-1) bits[i].get(r) [i].get [i] bits i get r bits[i].get(l-1) [i].get [i] bits i get l-1 l 1 ans.append(str(res)) ans.append ans append str(res) str res print("\n".join(ans)) print "\n".join(ans) "\n".join "\n" join ans c = ord(y) - ord('a') ord(y) - ord('a') c y = input().split() input().split() y bits = [BIT(n) for i in range(26)] [BIT(n) for i in range(26)] bits i = int(x) int(x) i res = 0 0 res ans = [] [] ans S = [ord(s) - ord('a') for s in input()[:-1]] [ord(s) - ord('a') for s in input()[:-1]] S r = int(y) int(y) r input = sys.stdin.readline sys.stdin.readline input n = int(input()) int(input()) n flag,x,y = input().split() input().split() flag l = int(x) int(x) l class BIT:
  def __init__(self,n):
    self.s = [0]*(n+1)
    self.n = n
  
  def add(self,val,idx):
    while idx < self.n+1:
      self.s[idx] = self.s[idx] + val
      idx += idx&(-idx)
    return
  
  def get(self,idx):
    res = 0
    while idx > 0:
      res = res + self.s[idx]
      idx -= idx&(-idx)
    return res
  class BIT:
  def __init__(self,n):
    self.s = [0]*(n+1)
    self.n = n
  
  def add(self,val,idx):
    while idx < self.n+1:
      self.s[idx] = self.s[idx] + val
      idx += idx&(-idx)
    return
  
  def get(self,idx):
    res = 0
    while idx > 0:
      res = res + self.s[idx]
      idx -= idx&(-idx)
    return res
  BIT Q = int(input()) int(input()) Q x,y = input().split() input().split() x res += (bits[i].get(r) > bits[i].get(l-1)) bits[i].get(r) > bits[i].get(l-1) res
class BIT:
  def __init__(self,n):
    self.s = [0]*(n+1)
    self.n = n
  
  def add(self,val,idx):
    while idx < self.n+1:
      self.s[idx] = self.s[idx] + val
      idx += idx&(-idx)
    return
  
  def get(self,idx):
    res = 0
    while idx > 0:
      res = res + self.s[idx]
      idx -= idx&(-idx)
    return res
 
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
 
n = int(input())
S = [ord(s) - ord('a') for s in input()[:-1]]
 
bits = [BIT(n) for i in range(26)]
 
for i,s in enumerate(S):
  bits[s].add(1,i+1)
 
Q = int(input())
ans = []
for _ in range(Q):  
  flag,x,y = input().split()

  if flag == "1":
    i = int(x)
    c = ord(y) - ord('a')
    bits[S[i-1]].add(-1,i)
    bits[c].add(1,i)
    S[i-1] = c
  else:
    l = int(x)
    r = int(y)
    res = 0
    for i in range(26):
      res += (bits[i].get(r) > bits[i].get(l-1))
    ans.append(str(res))

print("\n".join(ans))