class Bit():
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s


def enc(a):
    return ord(a) - ord('a')


N = int(input())
S = input()
bits = [Bit(N) for i in range(26)]

for i, s in enumerate(S):
    bits[enc(s)].add(i + 1, 1)


for _ in range(int(input())):
    t, l, r = input().split(" ")
    if t == '1':
        i = int(l)
        before = -1
        for before in range(26):
            if bits[before].sum(i) - bits[before].sum(i - 1) == 1:
                break
        after = enc(r)
        bits[before].add(i, -1)
        bits[after].add(i, 1)
    else:
        l, r = map(int, [l, r])
        ans = 0
        for c in range(26):
            if bits[c].sum(r) - bits[c].sum(l - 1) > 0:
                ans += 1
        print(ans) class Bit():
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s Bit def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

     __init__ self.size = n self.size self size n self.tree = [0] * (n + 1) self.tree self tree [0] * (n + 1) [0] 0 n + 1 n 1 self self n n def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

     add while i <= self.size:
            self.tree[i] += x
            i += i & -i

     i <= self.size i self.size self size self.tree[i] += x self.tree[i] self.tree self tree i x i += i & -i i i & -i i -i i self self i i x x def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s sum s = 0 s 0 while i > 0:
            s += self.tree[i]
            i -= i & -i
         i > 0 i 0 s += self.tree[i] s self.tree[i] self.tree self tree i i -= i & -i i i & -i i -i i return s s self self i i def enc(a):
    return ord(a) - ord('a') enc return ord(a) - ord('a') ord(a) - ord('a') ord(a) ord a ord('a') ord 'a' a a N = int(input()) N int(input()) int input() input S = input() S input() input Bit(N) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) Bit(N) Bit N bits = [Bit(N) for i in range(26)] bits [Bit(N) for i in range(26)] for i, s in enumerate(S):
    bits[enc(s)].add(i + 1, 1) i s enumerate(S) enumerate S bits[enc(s)].add(i + 1, 1) [enc(s)].add [enc(s)] bits enc(s) enc s add i + 1 i 1 1 for _ in range(int(input())):
    t, l, r = input().split(" ")
    if t == '1':
        i = int(l)
        before = -1
        for before in range(26):
            if bits[before].sum(i) - bits[before].sum(i - 1) == 1:
                break
        after = enc(r)
        bits[before].add(i, -1)
        bits[after].add(i, 1)
    else:
        l, r = map(int, [l, r])
        ans = 0
        for c in range(26):
            if bits[c].sum(r) - bits[c].sum(l - 1) > 0:
                ans += 1
        print(ans) _ range(int(input())) range int(input()) int input() input t, l, r = input().split(" ") t input().split(" ") ().split () input split " " l r if t == '1':
        i = int(l)
        before = -1
        for before in range(26):
            if bits[before].sum(i) - bits[before].sum(i - 1) == 1:
                break
        after = enc(r)
        bits[before].add(i, -1)
        bits[after].add(i, 1)
    else:
        l, r = map(int, [l, r])
        ans = 0
        for c in range(26):
            if bits[c].sum(r) - bits[c].sum(l - 1) > 0:
                ans += 1
        print(ans) t == '1' t '1' i = int(l) i int(l) int l before = -1 before -1 for before in range(26):
            if bits[before].sum(i) - bits[before].sum(i - 1) == 1:
                break
         before range(26) range 26 if bits[before].sum(i) - bits[before].sum(i - 1) == 1:
                break
         bits[before].sum(i) - bits[before].sum(i - 1) == 1 bits[before].sum(i) - bits[before].sum(i - 1) bits[before].sum(i) [before].sum [before] bits before sum i bits[before].sum(i - 1) [before].sum [before] bits before sum i - 1 i 1 1 break after = enc(r) after enc(r) enc r bits[before].add(i, -1) [before].add [before] bits before add i -1 bits[after].add(i, 1) [after].add [after] bits after add i 1 l, r = map(int, [l, r]) l map(int, [l, r]) map int [l, r] l r r ans = 0 ans 0 for c in range(26):
            if bits[c].sum(r) - bits[c].sum(l - 1) > 0:
                ans += 1
         c range(26) range 26 if bits[c].sum(r) - bits[c].sum(l - 1) > 0:
                ans += 1
         bits[c].sum(r) - bits[c].sum(l - 1) > 0 bits[c].sum(r) - bits[c].sum(l - 1) bits[c].sum(r) [c].sum [c] bits c sum r bits[c].sum(l - 1) [c].sum [c] bits c sum l - 1 l 1 0 ans += 1 ans 1 print(ans) print ans after = enc(r) enc(r) after S = input() input() S i = int(l) int(l) i r = map(int, [l, r]) map(int, [l, r]) r bits = [Bit(N) for i in range(26)] [Bit(N) for i in range(26)] bits l, r = map(int, [l, r]) map(int, [l, r]) l before = -1 -1 before N = int(input()) int(input()) N r = input().split(" ") input().split(" ") r class Bit():
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s class Bit():
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s Bit t, l, r = input().split(" ") input().split(" ") t l, r = input().split(" ") input().split(" ") l def enc(a):
    return ord(a) - ord('a') def enc(a):
    return ord(a) - ord('a') enc ans += 1 1 ans ans = 0 0 ans
class Bit():
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s


def enc(a):
    return ord(a) - ord('a')


N = int(input())
S = input()
bits = [Bit(N) for i in range(26)]

for i, s in enumerate(S):
    bits[enc(s)].add(i + 1, 1)


for _ in range(int(input())):
    t, l, r = input().split(" ")
    if t == '1':
        i = int(l)
        before = -1
        for before in range(26):
            if bits[before].sum(i) - bits[before].sum(i - 1) == 1:
                break
        after = enc(r)
        bits[before].add(i, -1)
        bits[after].add(i, 1)
    else:
        l, r = map(int, [l, r])
        ans = 0
        for c in range(26):
            if bits[c].sum(r) - bits[c].sum(l - 1) > 0:
                ans += 1
        print(ans)