#セグ木
from collections import deque
def f(L, R): return L|R # merge
def g(old, new): return old^new  # update
zero = 0 #零元

class segtree:
    def __init__(self, N, z):
        self.M = 1
        while self.M<N: self.M *= 2
        self.dat = [z] * (self.M*2-1)
        self.ZERO = z

    def update(self, x, idx, l=0, r=-1):
        if r==-1: r = self.M
        idx += self.M-1
        self.dat[idx] = g(self.dat[idx], x)
        while idx > 0:
            idx = (idx-1)//2
            self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2])

    def query(self, a, b=-1, idx=0, l=0, r=-1):
        if r==-1: r = self.M
        if b==-1: b = self.M
        q = deque([])
        q.append([l, r, 0])
        ret = self.ZERO
        while len(q):
            tmp = q.popleft()
            L = tmp[0]
            R = tmp[1]
            if R<=a or b<=L: continue
            elif a<=L and R<=b:
                ret = f(ret, self.dat[tmp[2]])
            else:
                q.append([L, (L+R)//2, tmp[2]*2+1])
                q.append([(L+R)//2, R, tmp[2]*2+2])
        return ret
n = int(input())
s = list(input())
q = int(input())
seg = segtree(n+1, 0)

for i in range(n):
    num = ord(s[i]) - ord("a")
    seg.update((1<<num), i)
for _ in range(q):
    a, b, c = input().split()
    b = int(b) - 1
    if a == "1":
        pre = ord(s[b]) - ord("a")
        now = ord(c) - ord("a")
        seg.update((1<<pre), b)
        seg.update((1<<now), b)
        s[b] = c
    else:
        q = seg.query(b, int(c))
        bin(q).count("1")
        print(bin(q).count("1")) from collections import deque def f(L, R): return L|R # merge f L L R R def g(old, new): return old^new  # update g old old new new zero = 0 zero 0 class segtree:
    def __init__(self, N, z):
        self.M = 1
        while self.M<N: self.M *= 2
        self.dat = [z] * (self.M*2-1)
        self.ZERO = z

    def update(self, x, idx, l=0, r=-1):
        if r==-1: r = self.M
        idx += self.M-1
        self.dat[idx] = g(self.dat[idx], x)
        while idx > 0:
            idx = (idx-1)//2
            self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2])

    def query(self, a, b=-1, idx=0, l=0, r=-1):
        if r==-1: r = self.M
        if b==-1: b = self.M
        q = deque([])
        q.append([l, r, 0])
        ret = self.ZERO
        while len(q):
            tmp = q.popleft()
            L = tmp[0]
            R = tmp[1]
            if R<=a or b<=L: continue
            elif a<=L and R<=b:
                ret = f(ret, self.dat[tmp[2]])
            else:
                q.append([L, (L+R)//2, tmp[2]*2+1])
                q.append([(L+R)//2, R, tmp[2]*2+2])
        return ret segtree def __init__(self, N, z):
        self.M = 1
        while self.M<N: self.M *= 2
        self.dat = [z] * (self.M*2-1)
        self.ZERO = z

     __init__ self.M = 1 self.M self M 1 while self.M<N: self.M *= 2
         self.M<N self.M self M N self.dat = [z] * (self.M*2-1) self.dat self dat [z] * (self.M*2-1) [z] z self.M*2-1 self.M*2 self.M self M 2 1 self.ZERO = z self.ZERO self ZERO z self self N N z z def update(self, x, idx, l=0, r=-1):
        if r==-1: r = self.M
        idx += self.M-1
        self.dat[idx] = g(self.dat[idx], x)
        while idx > 0:
            idx = (idx-1)//2
            self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2])

     update if r==-1: r = self.M
         r==-1 r -1 idx += self.M-1 idx self.M-1 self.M self M 1 self.dat[idx] = g(self.dat[idx], x) self.dat[idx] self.dat self dat idx g(self.dat[idx], x) g self.dat[idx] self.dat self dat idx x while idx > 0:
            idx = (idx-1)//2
            self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2])

     idx > 0 idx 0 idx = (idx-1)//2 idx (idx-1)//2 idx-1 idx 1 2 self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2]) self.dat[idx] self.dat self dat idx f(self.dat[idx*2+1], self.dat[idx*2+2]) f self.dat[idx*2+1] self.dat self dat idx*2+1 idx*2 idx 2 1 self.dat[idx*2+2] self.dat self dat idx*2+2 idx*2 idx 2 2 self self x x idx idx l=0 l 0 r=-1 r -1 def query(self, a, b=-1, idx=0, l=0, r=-1):
        if r==-1: r = self.M
        if b==-1: b = self.M
        q = deque([])
        q.append([l, r, 0])
        ret = self.ZERO
        while len(q):
            tmp = q.popleft()
            L = tmp[0]
            R = tmp[1]
            if R<=a or b<=L: continue
            elif a<=L and R<=b:
                ret = f(ret, self.dat[tmp[2]])
            else:
                q.append([L, (L+R)//2, tmp[2]*2+1])
                q.append([(L+R)//2, R, tmp[2]*2+2])
        return ret query if r==-1: r = self.M
         r==-1 r -1 if b==-1: b = self.M
         b==-1 b -1 q = deque([]) q deque([]) deque [] q.append([l, r, 0]) q.append q append [l, r, 0] l r 0 ret = self.ZERO ret self.ZERO self ZERO while len(q):
            tmp = q.popleft()
            L = tmp[0]
            R = tmp[1]
            if R<=a or b<=L: continue
            elif a<=L and R<=b:
                ret = f(ret, self.dat[tmp[2]])
            else:
                q.append([L, (L+R)//2, tmp[2]*2+1])
                q.append([(L+R)//2, R, tmp[2]*2+2])
         len(q) len q tmp = q.popleft() tmp q.popleft() q.popleft q popleft L = tmp[0] L tmp[0] tmp 0 R = tmp[1] R tmp[1] tmp 1 if R<=a or b<=L: continue
            elif a<=L and R<=b:
                ret = f(ret, self.dat[tmp[2]])
            else:
                q.append([L, (L+R)//2, tmp[2]*2+1])
                q.append([(L+R)//2, R, tmp[2]*2+2])
         R<=a or b<=L R<=a R a b<=L b L elif a<=L and R<=b:
                ret = f(ret, self.dat[tmp[2]])
             a<=L and R<=b a<=L a L R<=b R b ret = f(ret, self.dat[tmp[2]]) ret f(ret, self.dat[tmp[2]]) f ret self.dat[tmp[2]] self.dat self dat tmp[2] tmp 2 q.append([L, (L+R)//2, tmp[2]*2+1]) q.append q append [L, (L+R)//2, tmp[2]*2+1] L (L+R)//2 L+R L R 2 tmp[2]*2+1 tmp[2]*2 tmp[2] tmp 2 2 1 q.append([(L+R)//2, R, tmp[2]*2+2]) q.append q append [(L+R)//2, R, tmp[2]*2+2] (L+R)//2 L+R L R 2 R tmp[2]*2+2 tmp[2]*2 tmp[2] tmp 2 2 2 return ret ret self self a a b=-1 b -1 idx=0 idx 0 l=0 l 0 r=-1 r -1 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 seg = segtree(n+1, 0) seg segtree(n+1, 0) segtree n+1 n 1 0 for i in range(n):
    num = ord(s[i]) - ord("a")
    seg.update((1<<num), i) i range(n) range n num = ord(s[i]) - ord("a") num ord(s[i]) - ord("a") ord(s[i]) ord s[i] s i ord("a") ord "a" seg.update((1<<num), i) seg.update seg update 1<<num 1 num i for _ in range(q):
    a, b, c = input().split()
    b = int(b) - 1
    if a == "1":
        pre = ord(s[b]) - ord("a")
        now = ord(c) - ord("a")
        seg.update((1<<pre), b)
        seg.update((1<<now), b)
        s[b] = c
    else:
        q = seg.query(b, int(c))
        bin(q).count("1")
        print(bin(q).count("1")) _ range(q) range q a, b, c = input().split() a input().split() ().split () input split b c b = int(b) - 1 b int(b) - 1 int(b) int b 1 if a == "1":
        pre = ord(s[b]) - ord("a")
        now = ord(c) - ord("a")
        seg.update((1<<pre), b)
        seg.update((1<<now), b)
        s[b] = c
    else:
        q = seg.query(b, int(c))
        bin(q).count("1")
        print(bin(q).count("1")) a == "1" a "1" pre = ord(s[b]) - ord("a") pre ord(s[b]) - ord("a") ord(s[b]) ord s[b] s b ord("a") ord "a" now = ord(c) - ord("a") now ord(c) - ord("a") ord(c) ord c ord("a") ord "a" seg.update((1<<pre), b) seg.update seg update 1<<pre 1 pre b seg.update((1<<now), b) seg.update seg update 1<<now 1 now b s[b] = c s[b] s b c q = seg.query(b, int(c)) q seg.query(b, int(c)) seg.query seg query b int(c) int c bin(q).count("1") (q).count (q) bin q count "1" print(bin(q).count("1")) print bin(q).count("1") (q).count (q) bin q count "1" c = input().split() input().split() c a, b, c = input().split() input().split() a b = int(b) - 1 int(b) - 1 b now = ord(c) - ord("a") ord(c) - ord("a") now seg = segtree(n+1, 0) segtree(n+1, 0) seg q = seg.query(b, int(c)) seg.query(b, int(c)) q def f(L, R): return L|R # merge def f(L, R): return L|R # merge f n = int(input()) int(input()) n num = ord(s[i]) - ord("a") ord(s[i]) - ord("a") num def g(old, new): return old^new  # update def g(old, new): return old^new  # update g class segtree:
    def __init__(self, N, z):
        self.M = 1
        while self.M<N: self.M *= 2
        self.dat = [z] * (self.M*2-1)
        self.ZERO = z

    def update(self, x, idx, l=0, r=-1):
        if r==-1: r = self.M
        idx += self.M-1
        self.dat[idx] = g(self.dat[idx], x)
        while idx > 0:
            idx = (idx-1)//2
            self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2])

    def query(self, a, b=-1, idx=0, l=0, r=-1):
        if r==-1: r = self.M
        if b==-1: b = self.M
        q = deque([])
        q.append([l, r, 0])
        ret = self.ZERO
        while len(q):
            tmp = q.popleft()
            L = tmp[0]
            R = tmp[1]
            if R<=a or b<=L: continue
            elif a<=L and R<=b:
                ret = f(ret, self.dat[tmp[2]])
            else:
                q.append([L, (L+R)//2, tmp[2]*2+1])
                q.append([(L+R)//2, R, tmp[2]*2+2])
        return ret class segtree:
    def __init__(self, N, z):
        self.M = 1
        while self.M<N: self.M *= 2
        self.dat = [z] * (self.M*2-1)
        self.ZERO = z

    def update(self, x, idx, l=0, r=-1):
        if r==-1: r = self.M
        idx += self.M-1
        self.dat[idx] = g(self.dat[idx], x)
        while idx > 0:
            idx = (idx-1)//2
            self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2])

    def query(self, a, b=-1, idx=0, l=0, r=-1):
        if r==-1: r = self.M
        if b==-1: b = self.M
        q = deque([])
        q.append([l, r, 0])
        ret = self.ZERO
        while len(q):
            tmp = q.popleft()
            L = tmp[0]
            R = tmp[1]
            if R<=a or b<=L: continue
            elif a<=L and R<=b:
                ret = f(ret, self.dat[tmp[2]])
            else:
                q.append([L, (L+R)//2, tmp[2]*2+1])
                q.append([(L+R)//2, R, tmp[2]*2+2])
        return ret segtree b, c = input().split() input().split() b pre = ord(s[b]) - ord("a") ord(s[b]) - ord("a") pre zero = 0 0 zero s = list(input()) list(input()) s q = int(input()) int(input()) q
#セグ木
from collections import deque
def f(L, R): return L|R # merge
def g(old, new): return old^new  # update
zero = 0 #零元

class segtree:
    def __init__(self, N, z):
        self.M = 1
        while self.M<N: self.M *= 2
        self.dat = [z] * (self.M*2-1)
        self.ZERO = z

    def update(self, x, idx, l=0, r=-1):
        if r==-1: r = self.M
        idx += self.M-1
        self.dat[idx] = g(self.dat[idx], x)
        while idx > 0:
            idx = (idx-1)//2
            self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2])

    def query(self, a, b=-1, idx=0, l=0, r=-1):
        if r==-1: r = self.M
        if b==-1: b = self.M
        q = deque([])
        q.append([l, r, 0])
        ret = self.ZERO
        while len(q):
            tmp = q.popleft()
            L = tmp[0]
            R = tmp[1]
            if R<=a or b<=L: continue
            elif a<=L and R<=b:
                ret = f(ret, self.dat[tmp[2]])
            else:
                q.append([L, (L+R)//2, tmp[2]*2+1])
                q.append([(L+R)//2, R, tmp[2]*2+2])
        return ret
n = int(input())
s = list(input())
q = int(input())
seg = segtree(n+1, 0)

for i in range(n):
    num = ord(s[i]) - ord("a")
    seg.update((1<<num), i)
for _ in range(q):
    a, b, c = input().split()
    b = int(b) - 1
    if a == "1":
        pre = ord(s[b]) - ord("a")
        now = ord(c) - ord("a")
        seg.update((1<<pre), b)
        seg.update((1<<now), b)
        s[b] = c
    else:
        q = seg.query(b, int(c))
        bin(q).count("1")
        print(bin(q).count("1"))
