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()
seg = SegTree(N,set.union,set())
S = [set([ord(S[i])-97]) for i in range(N)]
seg.build(S)
Q=int(input())
for i in range(Q):
  *q, = input().split()
  if q[0] == '1':
    i, c = q[1:]
    seg.set_val(int(i)-1,set([ord(c)-97]))
  else:
    l,r = map(int,q[1:])
    print(len(seg.fold(l-1,r))) 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 seg = SegTree(N,set.union,set()) seg SegTree(N,set.union,set()) SegTree N set.union set union set() set set([ord(S[i])-97]) for i in range(N) for i in range(N) i range(N) range N for i in range(N) set([ord(S[i])-97]) set [ord(S[i])-97] ord(S[i])-97 ord(S[i]) ord S[i] S i 97 S = [set([ord(S[i])-97]) for i in range(N)] S [set([ord(S[i])-97]) for i in range(N)] seg.build(S) seg.build seg build S 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:]
    seg.set_val(int(i)-1,set([ord(c)-97]))
  else:
    l,r = map(int,q[1:])
    print(len(seg.fold(l-1,r))) i range(Q) range Q *q, = input().split() *q q input().split() ().split () input split if q[0] == '1':
    i, c = q[1:]
    seg.set_val(int(i)-1,set([ord(c)-97]))
  else:
    l,r = map(int,q[1:])
    print(len(seg.fold(l-1,r))) q[0] == '1' q[0] q 0 '1' i, c = q[1:] i q[1:] q 1: 1 c seg.set_val(int(i)-1,set([ord(c)-97])) seg.set_val seg set_val int(i)-1 int(i) int i 1 set([ord(c)-97]) set [ord(c)-97] ord(c)-97 ord(c) ord c 97 l,r = map(int,q[1:]) l map(int,q[1:]) map int q[1:] q 1: 1 r print(len(seg.fold(l-1,r))) print len(seg.fold(l-1,r)) len seg.fold(l-1,r) seg.fold seg fold l-1 l 1 r c = q[1:] q[1:] c 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 i, c = q[1:] q[1:] i S=input() input() S S = [set([ord(S[i])-97]) for i in range(N)] [set([ord(S[i])-97]) for i in range(N)] S seg = SegTree(N,set.union,set()) SegTree(N,set.union,set()) seg r = map(int,q[1:]) map(int,q[1:]) r N=int(input()) int(input()) N l,r = map(int,q[1:]) map(int,q[1:]) l Q=int(input()) int(input()) Q
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()
seg = SegTree(N,set.union,set())
S = [set([ord(S[i])-97]) for i in range(N)]
seg.build(S)
Q=int(input())
for i in range(Q):
  *q, = input().split()
  if q[0] == '1':
    i, c = q[1:]
    seg.set_val(int(i)-1,set([ord(c)-97]))
  else:
    l,r = map(int,q[1:])
    print(len(seg.fold(l-1,r)))