def main():
  import bisect
  
  n = int(input())
  s = list(input())
  q = int(input())
  
  d = {}
  for i in range(26):
    d[chr(ord('a')+i)] = []
  for i in range(n):
    d[s[i]].append(i)
  #print(d)
  
  for i in range(q):
    t,a,b = input().split()
    if t == '1':
      a = int(a)-1
      if s[a] == b:
        continue
      idx = bisect.bisect_left(d[s[a]],a)
      d[s[a]].pop(idx)
      bisect.insort_left(d[b],a)
      s[a] = b
    else:
      a = int(a)-1
      b = int(b)-1
      c = 0
      for i in range(26):
        idx = bisect.bisect_left(d[chr(ord('a')+i)],a)
        if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b:
          c += 1
      print(c)
  
main() def main():
  import bisect
  
  n = int(input())
  s = list(input())
  q = int(input())
  
  d = {}
  for i in range(26):
    d[chr(ord('a')+i)] = []
  for i in range(n):
    d[s[i]].append(i)
  #print(d)
  
  for i in range(q):
    t,a,b = input().split()
    if t == '1':
      a = int(a)-1
      if s[a] == b:
        continue
      idx = bisect.bisect_left(d[s[a]],a)
      d[s[a]].pop(idx)
      bisect.insort_left(d[b],a)
      s[a] = b
    else:
      a = int(a)-1
      b = int(b)-1
      c = 0
      for i in range(26):
        idx = bisect.bisect_left(d[chr(ord('a')+i)],a)
        if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b:
          c += 1
      print(c)
   main import bisect bisect 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 d = {} d {} for i in range(26):
    d[chr(ord('a')+i)] = []
   i range(26) range 26 d[chr(ord('a')+i)] = [] d[chr(ord('a')+i)] d chr(ord('a')+i) chr ord('a')+i ord('a') ord 'a' i [] for i in range(n):
    d[s[i]].append(i)
  #print(d)
  
   i range(n) range n d[s[i]].append(i) [s[i]].append [s[i]] d s[i] s i append i for i in range(q):
    t,a,b = input().split()
    if t == '1':
      a = int(a)-1
      if s[a] == b:
        continue
      idx = bisect.bisect_left(d[s[a]],a)
      d[s[a]].pop(idx)
      bisect.insort_left(d[b],a)
      s[a] = b
    else:
      a = int(a)-1
      b = int(b)-1
      c = 0
      for i in range(26):
        idx = bisect.bisect_left(d[chr(ord('a')+i)],a)
        if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b:
          c += 1
      print(c)
   i range(q) range q t,a,b = input().split() t input().split() ().split () input split a b if t == '1':
      a = int(a)-1
      if s[a] == b:
        continue
      idx = bisect.bisect_left(d[s[a]],a)
      d[s[a]].pop(idx)
      bisect.insort_left(d[b],a)
      s[a] = b
    else:
      a = int(a)-1
      b = int(b)-1
      c = 0
      for i in range(26):
        idx = bisect.bisect_left(d[chr(ord('a')+i)],a)
        if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b:
          c += 1
      print(c)
   t == '1' t '1' a = int(a)-1 a int(a)-1 int(a) int a 1 if s[a] == b:
        continue
       s[a] == b s[a] s a b continue idx = bisect.bisect_left(d[s[a]],a) idx bisect.bisect_left(d[s[a]],a) bisect.bisect_left bisect bisect_left d[s[a]] d s[a] s a a d[s[a]].pop(idx) [s[a]].pop [s[a]] d s[a] s a pop idx bisect.insort_left(d[b],a) bisect.insort_left bisect insort_left d[b] d b a s[a] = b s[a] s a b a = int(a)-1 a int(a)-1 int(a) int a 1 b = int(b)-1 b int(b)-1 int(b) int b 1 c = 0 c 0 for i in range(26):
        idx = bisect.bisect_left(d[chr(ord('a')+i)],a)
        if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b:
          c += 1
       i range(26) range 26 idx = bisect.bisect_left(d[chr(ord('a')+i)],a) idx bisect.bisect_left(d[chr(ord('a')+i)],a) bisect.bisect_left bisect bisect_left d[chr(ord('a')+i)] d chr(ord('a')+i) chr ord('a')+i ord('a') ord 'a' i a if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b:
          c += 1
       idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b idx < len(d[chr(ord('a')+i)]) idx len(d[chr(ord('a')+i)]) len d[chr(ord('a')+i)] d chr(ord('a')+i) chr ord('a')+i ord('a') ord 'a' i d[chr(ord('a')+i)][idx] <= b d[chr(ord('a')+i)][idx] [chr(ord('a')+i)] d chr(ord('a')+i) chr ord('a')+i ord('a') ord 'a' i idx b c += 1 c 1 print(c) print c main() main def main():
  import bisect
  
  n = int(input())
  s = list(input())
  q = int(input())
  
  d = {}
  for i in range(26):
    d[chr(ord('a')+i)] = []
  for i in range(n):
    d[s[i]].append(i)
  #print(d)
  
  for i in range(q):
    t,a,b = input().split()
    if t == '1':
      a = int(a)-1
      if s[a] == b:
        continue
      idx = bisect.bisect_left(d[s[a]],a)
      d[s[a]].pop(idx)
      bisect.insort_left(d[b],a)
      s[a] = b
    else:
      a = int(a)-1
      b = int(b)-1
      c = 0
      for i in range(26):
        idx = bisect.bisect_left(d[chr(ord('a')+i)],a)
        if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b:
          c += 1
      print(c)
   def main():
  import bisect
  
  n = int(input())
  s = list(input())
  q = int(input())
  
  d = {}
  for i in range(26):
    d[chr(ord('a')+i)] = []
  for i in range(n):
    d[s[i]].append(i)
  #print(d)
  
  for i in range(q):
    t,a,b = input().split()
    if t == '1':
      a = int(a)-1
      if s[a] == b:
        continue
      idx = bisect.bisect_left(d[s[a]],a)
      d[s[a]].pop(idx)
      bisect.insort_left(d[b],a)
      s[a] = b
    else:
      a = int(a)-1
      b = int(b)-1
      c = 0
      for i in range(26):
        idx = bisect.bisect_left(d[chr(ord('a')+i)],a)
        if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b:
          c += 1
      print(c)
   main
def main():
  import bisect
  
  n = int(input())
  s = list(input())
  q = int(input())
  
  d = {}
  for i in range(26):
    d[chr(ord('a')+i)] = []
  for i in range(n):
    d[s[i]].append(i)
  #print(d)
  
  for i in range(q):
    t,a,b = input().split()
    if t == '1':
      a = int(a)-1
      if s[a] == b:
        continue
      idx = bisect.bisect_left(d[s[a]],a)
      d[s[a]].pop(idx)
      bisect.insort_left(d[b],a)
      s[a] = b
    else:
      a = int(a)-1
      b = int(b)-1
      c = 0
      for i in range(26):
        idx = bisect.bisect_left(d[chr(ord('a')+i)],a)
        if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b:
          c += 1
      print(c)
  
main()