class SegTree:
    """ segment tree with point modification and range product. """
    # # https://yukicoder.me/submissions/452850
    def __init__(self, N, data_f = min, data_unit=1<<30):
        self.N = N
        self.data_f = data_f
        self.data_unit = data_unit
        self.data = [self.data_unit] * (N + N)

    def build(self, raw_data):
        data = self.data
        f = self.data_f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

    def set_val(self, i, x):
        data = self.data
        f = self.data_f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

    def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.data_unit
        data = self.data
        f = self.data_f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)
      
N=int(input())
S=input()
data = [[0]*N for _ in range(26)]
di = {}
for i in range(N):
  data[ord(S[i])-97][i] = 1
  di[i] = S[i]

seg = [SegTree(N,max,0) for _ in range(26)]
for i in range(26):
  seg[i].build(data[i])
Q=int(input())
for i in range(Q):
  *q, = input().split()
  if q[0] == '1':
    i, c = q[1:]
    i = int(i)-1
    c_old = di[i]
    di[i] = c
    seg[ord(c_old)-97].set_val(i,0)
    seg[ord(c)-97].set_val(i,1)
  else:
    l,r = map(int,q[1:])
    ans=0
    for i in range(26):
      ans += seg[i].fold(l-1,r)
    print(ans) class SegTree:
    """ segment tree with point modification and range product. """
    # # https://yukicoder.me/submissions/452850
    def __init__(self, N, data_f = min, data_unit=1<<30):
        self.N = N
        self.data_f = data_f
        self.data_unit = data_unit
        self.data = [self.data_unit] * (N + N)

    def build(self, raw_data):
        data = self.data
        f = self.data_f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

    def set_val(self, i, x):
        data = self.data
        f = self.data_f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

    def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.data_unit
        data = self.data
        f = self.data_f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)
       SegTree """ segment tree with point modification and range product. """ def __init__(self, N, data_f = min, data_unit=1<<30):
        self.N = N
        self.data_f = data_f
        self.data_unit = data_unit
        self.data = [self.data_unit] * (N + N)

     __init__ self.N = N self.N self N N self.data_f = data_f self.data_f self data_f data_f self.data_unit = data_unit self.data_unit self data_unit data_unit self.data = [self.data_unit] * (N + N) self.data self data [self.data_unit] * (N + N) [self.data_unit] self.data_unit self data_unit N + N N N self self N N data_f = min data_f min data_unit=1<<30 data_unit 1<<30 1 30 def build(self, raw_data):
        data = self.data
        f = self.data_f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

     build data = self.data data self.data self data f = self.data_f f self.data_f self data_f N = self.N N self.N self N data[N:] = raw_data[:] data[N:] data N: N raw_data[:] raw_data : for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

     i range(N - 1, 0, -1) range N - 1 N 1 0 -1 data[i] = f(data[i << 1], data[i << 1 | 1]) data[i] data i f(data[i << 1], data[i << 1 | 1]) f data[i << 1] data i << 1 i 1 data[i << 1 | 1] data i << 1 | 1 i << 1 i 1 1 self self raw_data raw_data def set_val(self, i, x):
        data = self.data
        f = self.data_f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

     set_val data = self.data data self.data self data f = self.data_f f self.data_f self data_f i += self.N i self.N self N data[i] = x data[i] data i x while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

     i > 1 i 1 data[i >> 1] = f(data[i], data[i ^ 1]) data[i >> 1] data i >> 1 i 1 f(data[i], data[i ^ 1]) f data[i] data i data[i ^ 1] data i ^ 1 i 1 i >>= 1 i 1 self self i i x x def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.data_unit
        data = self.data
        f = self.data_f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)
       fold """ compute for [L, R) """ vL = vR = self.data_unit vL self.data_unit self data_unit = vR = self.data_unit vR self.data_unit data = self.data data self.data self data f = self.data_f f self.data_f self data_f L += self.N L self.N self N R += self.N R self.N self N while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
         L < R L R if L & 1:
                vL = f(vL, data[L])
                L += 1
             L & 1 L 1 vL = f(vL, data[L]) vL f(vL, data[L]) f vL data[L] data L L += 1 L 1 if R & 1:
                R -= 1
                vR = f(data[R], vR)
             R & 1 R 1 R -= 1 R 1 vR = f(data[R], vR) vR f(data[R], vR) f data[R] data R vR L >>= 1 L 1 R >>= 1 R 1 return f(vL, vR) f(vL, vR) f vL vR self self L L R R N=int(input()) N int(input()) int input() input S=input() S input() input [0]*N for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [0]*N [0] 0 N data = [[0]*N for _ in range(26)] data [[0]*N for _ in range(26)] di = {} di {} for i in range(N):
  data[ord(S[i])-97][i] = 1
  di[i] = S[i] i range(N) range N data[ord(S[i])-97][i] = 1 data[ord(S[i])-97][i] [ord(S[i])-97] data ord(S[i])-97 ord(S[i]) ord S[i] S i 97 i 1 di[i] = S[i] di[i] di i S[i] S i SegTree(N,max,0) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) SegTree(N,max,0) SegTree N max 0 seg = [SegTree(N,max,0) for _ in range(26)] seg [SegTree(N,max,0) for _ in range(26)] for i in range(26):
  seg[i].build(data[i]) i range(26) range 26 seg[i].build(data[i]) [i].build [i] seg i build data[i] data i Q=int(input()) Q int(input()) int input() input for i in range(Q):
  *q, = input().split()
  if q[0] == '1':
    i, c = q[1:]
    i = int(i)-1
    c_old = di[i]
    di[i] = c
    seg[ord(c_old)-97].set_val(i,0)
    seg[ord(c)-97].set_val(i,1)
  else:
    l,r = map(int,q[1:])
    ans=0
    for i in range(26):
      ans += seg[i].fold(l-1,r)
    print(ans) i range(Q) range Q *q, = input().split() *q q input().split() ().split () input split if q[0] == '1':
    i, c = q[1:]
    i = int(i)-1
    c_old = di[i]
    di[i] = c
    seg[ord(c_old)-97].set_val(i,0)
    seg[ord(c)-97].set_val(i,1)
  else:
    l,r = map(int,q[1:])
    ans=0
    for i in range(26):
      ans += seg[i].fold(l-1,r)
    print(ans) q[0] == '1' q[0] q 0 '1' i, c = q[1:] i q[1:] q 1: 1 c i = int(i)-1 i int(i)-1 int(i) int i 1 c_old = di[i] c_old di[i] di i di[i] = c di[i] di i c seg[ord(c_old)-97].set_val(i,0) [ord(c_old)-97].set_val [ord(c_old)-97] seg ord(c_old)-97 ord(c_old) ord c_old 97 set_val i 0 seg[ord(c)-97].set_val(i,1) [ord(c)-97].set_val [ord(c)-97] seg ord(c)-97 ord(c) ord c 97 set_val i 1 l,r = map(int,q[1:]) l map(int,q[1:]) map int q[1:] q 1: 1 r ans=0 ans 0 for i in range(26):
      ans += seg[i].fold(l-1,r)
     i range(26) range 26 ans += seg[i].fold(l-1,r) ans seg[i].fold(l-1,r) [i].fold [i] seg i fold l-1 l 1 r print(ans) print ans seg = [SegTree(N,max,0) for _ in range(26)] [SegTree(N,max,0) for _ in range(26)] seg data = [[0]*N for _ in range(26)] [[0]*N for _ in range(26)] data c_old = di[i] di[i] c_old class SegTree:
    """ segment tree with point modification and range product. """
    # # https://yukicoder.me/submissions/452850
    def __init__(self, N, data_f = min, data_unit=1<<30):
        self.N = N
        self.data_f = data_f
        self.data_unit = data_unit
        self.data = [self.data_unit] * (N + N)

    def build(self, raw_data):
        data = self.data
        f = self.data_f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

    def set_val(self, i, x):
        data = self.data
        f = self.data_f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

    def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.data_unit
        data = self.data
        f = self.data_f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)
       class SegTree:
    """ segment tree with point modification and range product. """
    # # https://yukicoder.me/submissions/452850
    def __init__(self, N, data_f = min, data_unit=1<<30):
        self.N = N
        self.data_f = data_f
        self.data_unit = data_unit
        self.data = [self.data_unit] * (N + N)

    def build(self, raw_data):
        data = self.data
        f = self.data_f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

    def set_val(self, i, x):
        data = self.data
        f = self.data_f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

    def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.data_unit
        data = self.data
        f = self.data_f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)
       SegTree di = {} {} di ans=0 0 ans S=input() input() S i, c = q[1:] q[1:] i i = int(i)-1 int(i)-1 i Q=int(input()) int(input()) Q N=int(input()) int(input()) N r = map(int,q[1:]) map(int,q[1:]) r ans += seg[i].fold(l-1,r) seg[i].fold(l-1,r) ans c = q[1:] q[1:] c l,r = map(int,q[1:]) map(int,q[1:]) l
class SegTree:
    """ segment tree with point modification and range product. """
    # # https://yukicoder.me/submissions/452850
    def __init__(self, N, data_f = min, data_unit=1<<30):
        self.N = N
        self.data_f = data_f
        self.data_unit = data_unit
        self.data = [self.data_unit] * (N + N)

    def build(self, raw_data):
        data = self.data
        f = self.data_f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

    def set_val(self, i, x):
        data = self.data
        f = self.data_f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

    def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.data_unit
        data = self.data
        f = self.data_f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)
      
N=int(input())
S=input()
data = [[0]*N for _ in range(26)]
di = {}
for i in range(N):
  data[ord(S[i])-97][i] = 1
  di[i] = S[i]

seg = [SegTree(N,max,0) for _ in range(26)]
for i in range(26):
  seg[i].build(data[i])
Q=int(input())
for i in range(Q):
  *q, = input().split()
  if q[0] == '1':
    i, c = q[1:]
    i = int(i)-1
    c_old = di[i]
    di[i] = c
    seg[ord(c_old)-97].set_val(i,0)
    seg[ord(c)-97].set_val(i,1)
  else:
    l,r = map(int,q[1:])
    ans=0
    for i in range(26):
      ans += seg[i].fold(l-1,r)
    print(ans)