class BIT:
  from operator import add, sub, mul, floordiv
  X_unit = 0
  X_f = add
  X_f_rev = sub

  def __init__(self, seq):
    N = len(seq)
    self.N = N
    self.X = seq[:]
    for i in range(self.N):
      j = i + ((i+1) & -(i+1))
      if j < self.N:
        self.X[j] = self.X_f(self.X[i], self.X[j])
  
  def set_val(self, i, x):
    while(i < self.N):
      self.X[i] = self.X_f(self.X[i], x)
      i += (i+1) & -(i+1)

  def cum_val(self, i):
    res = self.X_unit
    while(i > -1):
      res = self.X_f(res, self.X[i])
      i -= (i+1) & -(i+1)
    return res
  
  #区間[L, R)
  def fold(self, L, R):
    return self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1))
  
  def bisect_left(self, w):
    if w > self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w <= self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
  def bisect_right(self, w):
    if w >= self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w < self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
  def lower_bound(self, w):
    ans = self.bisect_right(self.cum_val(w))
    if ans == self.N:
      return -1
    else:
      return ans
  
  def upper_bound(self, w):
    ans = self.bisect_left(self.cum_val(w-1))
    return ans

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

L = [BIT([0]*N) for _ in range(26)]

for i in range(N):
  L[ord(S[i])-97].set_val(i, 1)

Q = int(input())

for _ in range(Q):
  q, a, b = input().split()
  if q == "1":
    a = int(a)
    L[ord(S[a-1])-97].set_val(a-1, -1)
    L[ord(b)-97].set_val(a-1, 1)
    S[a-1] = b
  else:
    a, b = int(a), int(b)
    ans = 0
    for i in range(26):
      if L[i].fold(a-1, b) >= 1:
        ans += 1
    print(ans) class BIT:
  from operator import add, sub, mul, floordiv
  X_unit = 0
  X_f = add
  X_f_rev = sub

  def __init__(self, seq):
    N = len(seq)
    self.N = N
    self.X = seq[:]
    for i in range(self.N):
      j = i + ((i+1) & -(i+1))
      if j < self.N:
        self.X[j] = self.X_f(self.X[i], self.X[j])
  
  def set_val(self, i, x):
    while(i < self.N):
      self.X[i] = self.X_f(self.X[i], x)
      i += (i+1) & -(i+1)

  def cum_val(self, i):
    res = self.X_unit
    while(i > -1):
      res = self.X_f(res, self.X[i])
      i -= (i+1) & -(i+1)
    return res
  
  #区間[L, R)
  def fold(self, L, R):
    return self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1))
  
  def bisect_left(self, w):
    if w > self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w <= self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
  def bisect_right(self, w):
    if w >= self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w < self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
  def lower_bound(self, w):
    ans = self.bisect_right(self.cum_val(w))
    if ans == self.N:
      return -1
    else:
      return ans
  
  def upper_bound(self, w):
    ans = self.bisect_left(self.cum_val(w-1))
    return ans BIT from operator import add, sub, mul, floordiv X_unit = 0 X_unit 0 X_f = add X_f add X_f_rev = sub X_f_rev sub def __init__(self, seq):
    N = len(seq)
    self.N = N
    self.X = seq[:]
    for i in range(self.N):
      j = i + ((i+1) & -(i+1))
      if j < self.N:
        self.X[j] = self.X_f(self.X[i], self.X[j])
  
   __init__ N = len(seq) N len(seq) len seq self.N = N self.N self N N self.X = seq[:] self.X self X seq[:] seq : for i in range(self.N):
      j = i + ((i+1) & -(i+1))
      if j < self.N:
        self.X[j] = self.X_f(self.X[i], self.X[j])
  
   i range(self.N) range self.N self N j = i + ((i+1) & -(i+1)) j i + ((i+1) & -(i+1)) i (i+1) & -(i+1) i+1 i 1 -(i+1) i+1 i 1 if j < self.N:
        self.X[j] = self.X_f(self.X[i], self.X[j])
  
   j < self.N j self.N self N self.X[j] = self.X_f(self.X[i], self.X[j]) self.X[j] self.X self X j self.X_f(self.X[i], self.X[j]) self.X_f self X_f self.X[i] self.X self X i self.X[j] self.X self X j self self seq seq def set_val(self, i, x):
    while(i < self.N):
      self.X[i] = self.X_f(self.X[i], x)
      i += (i+1) & -(i+1)

   set_val while(i < self.N):
      self.X[i] = self.X_f(self.X[i], x)
      i += (i+1) & -(i+1)

   i < self.N i self.N self N self.X[i] = self.X_f(self.X[i], x) self.X[i] self.X self X i self.X_f(self.X[i], x) self.X_f self X_f self.X[i] self.X self X i x i += (i+1) & -(i+1) i (i+1) & -(i+1) i+1 i 1 -(i+1) i+1 i 1 self self i i x x def cum_val(self, i):
    res = self.X_unit
    while(i > -1):
      res = self.X_f(res, self.X[i])
      i -= (i+1) & -(i+1)
    return res
  
  #区間[L, R)
   cum_val res = self.X_unit res self.X_unit self X_unit while(i > -1):
      res = self.X_f(res, self.X[i])
      i -= (i+1) & -(i+1)
     i > -1 i -1 res = self.X_f(res, self.X[i]) res self.X_f(res, self.X[i]) self.X_f self X_f res self.X[i] self.X self X i i -= (i+1) & -(i+1) i (i+1) & -(i+1) i+1 i 1 -(i+1) i+1 i 1 return res res self self i i def fold(self, L, R):
    return self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1))
  
   fold return self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1)) self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1)) self.X_f_rev self X_f_rev self.cum_val(R-1) self.cum_val self cum_val R-1 R 1 self.cum_val(L-1) self.cum_val self cum_val L-1 L 1 self self L L R R def bisect_left(self, w):
    if w > self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w <= self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
   bisect_left if w > self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
     w > self.cum_val(self.N - 1) w self.cum_val(self.N - 1) self.cum_val self cum_val self.N - 1 self.N self N 1 return self.N self.N self N elif self.N == 2:
      return 1
     self.N == 2 self.N self N 2 return 1 1 n = 2**((self.N - 1).bit_length() - 1) n 2**((self.N - 1).bit_length() - 1) 2 (self.N - 1).bit_length() - 1 (self.N - 1).bit_length() self.N - 1).bit_length self.N - 1 self.N self N 1 bit_length 1 res = 0 res 0 while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w <= self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
     n if res + n - 1 > self.N - 1:
        n //= 2
        continue
       res + n - 1 > self.N - 1 res + n - 1 res + n res n 1 self.N - 1 self.N self N 1 n //= 2 n 2 continue if w <= self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
     w <= self.X[res + n - 1] w self.X[res + n - 1] self.X self X res + n - 1 res + n res n 1 n //= 2 n 2 w -= self.X[res + n - 1] w self.X[res + n - 1] self.X self X res + n - 1 res + n res n 1 res += n res n n //= 2 n 2 return res res self self w w def bisect_right(self, w):
    if w >= self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w < self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
   bisect_right if w >= self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
     w >= self.cum_val(self.N - 1) w self.cum_val(self.N - 1) self.cum_val self cum_val self.N - 1 self.N self N 1 return self.N self.N self N elif self.N == 2:
      return 1
     self.N == 2 self.N self N 2 return 1 1 n = 2**((self.N - 1).bit_length() - 1) n 2**((self.N - 1).bit_length() - 1) 2 (self.N - 1).bit_length() - 1 (self.N - 1).bit_length() self.N - 1).bit_length self.N - 1 self.N self N 1 bit_length 1 res = 0 res 0 while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w < self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
     n if res + n - 1 > self.N - 1:
        n //= 2
        continue
       res + n - 1 > self.N - 1 res + n - 1 res + n res n 1 self.N - 1 self.N self N 1 n //= 2 n 2 continue if w < self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
     w < self.X[res + n - 1] w self.X[res + n - 1] self.X self X res + n - 1 res + n res n 1 n //= 2 n 2 w -= self.X[res + n - 1] w self.X[res + n - 1] self.X self X res + n - 1 res + n res n 1 res += n res n n //= 2 n 2 return res res self self w w def lower_bound(self, w):
    ans = self.bisect_right(self.cum_val(w))
    if ans == self.N:
      return -1
    else:
      return ans
  
   lower_bound ans = self.bisect_right(self.cum_val(w)) ans self.bisect_right(self.cum_val(w)) self.bisect_right self bisect_right self.cum_val(w) self.cum_val self cum_val w if ans == self.N:
      return -1
    else:
      return ans
  
   ans == self.N ans self.N self N return -1 -1 return ans ans self self w w def upper_bound(self, w):
    ans = self.bisect_left(self.cum_val(w-1))
    return ans upper_bound ans = self.bisect_left(self.cum_val(w-1)) ans self.bisect_left(self.cum_val(w-1)) self.bisect_left self bisect_left self.cum_val(w-1) self.cum_val self cum_val w-1 w 1 return ans ans self self w w N = int(input()) N int(input()) int input() input S = list(input()) S list(input()) list input() input BIT([0]*N) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BIT([0]*N) BIT [0]*N [0] 0 N L = [BIT([0]*N) for _ in range(26)] L [BIT([0]*N) for _ in range(26)] for i in range(N):
  L[ord(S[i])-97].set_val(i, 1) i range(N) range N L[ord(S[i])-97].set_val(i, 1) [ord(S[i])-97].set_val [ord(S[i])-97] L ord(S[i])-97 ord(S[i]) ord S[i] S i 97 set_val i 1 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
  q, a, b = input().split()
  if q == "1":
    a = int(a)
    L[ord(S[a-1])-97].set_val(a-1, -1)
    L[ord(b)-97].set_val(a-1, 1)
    S[a-1] = b
  else:
    a, b = int(a), int(b)
    ans = 0
    for i in range(26):
      if L[i].fold(a-1, b) >= 1:
        ans += 1
    print(ans) _ range(Q) range Q q, a, b = input().split() q input().split() ().split () input split a b if q == "1":
    a = int(a)
    L[ord(S[a-1])-97].set_val(a-1, -1)
    L[ord(b)-97].set_val(a-1, 1)
    S[a-1] = b
  else:
    a, b = int(a), int(b)
    ans = 0
    for i in range(26):
      if L[i].fold(a-1, b) >= 1:
        ans += 1
    print(ans) q == "1" q "1" a = int(a) a int(a) int a L[ord(S[a-1])-97].set_val(a-1, -1) [ord(S[a-1])-97].set_val [ord(S[a-1])-97] L ord(S[a-1])-97 ord(S[a-1]) ord S[a-1] S a-1 a 1 97 set_val a-1 a 1 -1 L[ord(b)-97].set_val(a-1, 1) [ord(b)-97].set_val [ord(b)-97] L ord(b)-97 ord(b) ord b 97 set_val a-1 a 1 1 S[a-1] = b S[a-1] S a-1 a 1 b a, b = int(a), int(b) a int(a) int a b int(b) int b ans = 0 ans 0 for i in range(26):
      if L[i].fold(a-1, b) >= 1:
        ans += 1
     i range(26) range 26 if L[i].fold(a-1, b) >= 1:
        ans += 1
     L[i].fold(a-1, b) >= 1 L[i].fold(a-1, b) [i].fold [i] L i fold a-1 a 1 b 1 ans += 1 ans 1 print(ans) print ans a = int(a) int(a) a ans += 1 1 ans class BIT:
  from operator import add, sub, mul, floordiv
  X_unit = 0
  X_f = add
  X_f_rev = sub

  def __init__(self, seq):
    N = len(seq)
    self.N = N
    self.X = seq[:]
    for i in range(self.N):
      j = i + ((i+1) & -(i+1))
      if j < self.N:
        self.X[j] = self.X_f(self.X[i], self.X[j])
  
  def set_val(self, i, x):
    while(i < self.N):
      self.X[i] = self.X_f(self.X[i], x)
      i += (i+1) & -(i+1)

  def cum_val(self, i):
    res = self.X_unit
    while(i > -1):
      res = self.X_f(res, self.X[i])
      i -= (i+1) & -(i+1)
    return res
  
  #区間[L, R)
  def fold(self, L, R):
    return self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1))
  
  def bisect_left(self, w):
    if w > self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w <= self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
  def bisect_right(self, w):
    if w >= self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w < self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
  def lower_bound(self, w):
    ans = self.bisect_right(self.cum_val(w))
    if ans == self.N:
      return -1
    else:
      return ans
  
  def upper_bound(self, w):
    ans = self.bisect_left(self.cum_val(w-1))
    return ans class BIT:
  from operator import add, sub, mul, floordiv
  X_unit = 0
  X_f = add
  X_f_rev = sub

  def __init__(self, seq):
    N = len(seq)
    self.N = N
    self.X = seq[:]
    for i in range(self.N):
      j = i + ((i+1) & -(i+1))
      if j < self.N:
        self.X[j] = self.X_f(self.X[i], self.X[j])
  
  def set_val(self, i, x):
    while(i < self.N):
      self.X[i] = self.X_f(self.X[i], x)
      i += (i+1) & -(i+1)

  def cum_val(self, i):
    res = self.X_unit
    while(i > -1):
      res = self.X_f(res, self.X[i])
      i -= (i+1) & -(i+1)
    return res
  
  #区間[L, R)
  def fold(self, L, R):
    return self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1))
  
  def bisect_left(self, w):
    if w > self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w <= self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
  def bisect_right(self, w):
    if w >= self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w < self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
  def lower_bound(self, w):
    ans = self.bisect_right(self.cum_val(w))
    if ans == self.N:
      return -1
    else:
      return ans
  
  def upper_bound(self, w):
    ans = self.bisect_left(self.cum_val(w-1))
    return ans BIT S = list(input()) list(input()) S q, a, b = input().split() input().split() q Q = int(input()) int(input()) Q b = input().split() input().split() b N = int(input()) int(input()) N a, b = input().split() input().split() a ans = 0 0 ans L = [BIT([0]*N) for _ in range(26)] [BIT([0]*N) for _ in range(26)] L b = int(a), int(b) int(b) b a, b = int(a), int(b) int(a) a
class BIT:
  from operator import add, sub, mul, floordiv
  X_unit = 0
  X_f = add
  X_f_rev = sub

  def __init__(self, seq):
    N = len(seq)
    self.N = N
    self.X = seq[:]
    for i in range(self.N):
      j = i + ((i+1) & -(i+1))
      if j < self.N:
        self.X[j] = self.X_f(self.X[i], self.X[j])
  
  def set_val(self, i, x):
    while(i < self.N):
      self.X[i] = self.X_f(self.X[i], x)
      i += (i+1) & -(i+1)

  def cum_val(self, i):
    res = self.X_unit
    while(i > -1):
      res = self.X_f(res, self.X[i])
      i -= (i+1) & -(i+1)
    return res
  
  #区間[L, R)
  def fold(self, L, R):
    return self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1))
  
  def bisect_left(self, w):
    if w > self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w <= self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
  def bisect_right(self, w):
    if w >= self.cum_val(self.N - 1):
      return self.N
    elif self.N == 2:
      return 1
    n = 2**((self.N - 1).bit_length() - 1)
    res = 0
    while(n):
      if res + n - 1 > self.N - 1:
        n //= 2
        continue
      if w < self.X[res + n - 1]:
        n //= 2
      else:
        w -= self.X[res + n - 1]
        res += n
        n //= 2
    return res
  
  def lower_bound(self, w):
    ans = self.bisect_right(self.cum_val(w))
    if ans == self.N:
      return -1
    else:
      return ans
  
  def upper_bound(self, w):
    ans = self.bisect_left(self.cum_val(w-1))
    return ans

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

L = [BIT([0]*N) for _ in range(26)]

for i in range(N):
  L[ord(S[i])-97].set_val(i, 1)

Q = int(input())

for _ in range(Q):
  q, a, b = input().split()
  if q == "1":
    a = int(a)
    L[ord(S[a-1])-97].set_val(a-1, -1)
    L[ord(b)-97].set_val(a-1, 1)
    S[a-1] = b
  else:
    a, b = int(a), int(b)
    ans = 0
    for i in range(26):
      if L[i].fold(a-1, b) >= 1:
        ans += 1
    print(ans)