# Binary Indexed Tree (Fenwick Tree)
class BIT():
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

    def add(self, i, value):
        i = i + 1
        while i <= self.n:
            self.bit[i] += value
            i += i & -i

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

    def sum(self, l, r):
        return self._sum(r) - self._sum(l)

n = int(input())
S = input()
q = int(input())
Query = [input().split() for _ in range(q)]

bits = [BIT(n) for i in range(26)]
s = []
for i,c in enumerate(S):
    bits[ord(c) - ord("a")].add(i,1)
    s.append(c)

for q_type,fr,to in Query:
    if q_type == "1":
        i = int(fr)-1
        bits[ord(s[i]) - ord("a")].add(i,-1)
        bits[ord(to) - ord("a")].add(i,1)
        s[i] = to
    else:
        l,r = int(fr)-1,int(to)
        tmp = 0
        for i in range(26):
            if bits[i].sum(l,r):
                tmp += 1
        print(tmp)
 class BIT():
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

    def add(self, i, value):
        i = i + 1
        while i <= self.n:
            self.bit[i] += value
            i += i & -i

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

    def sum(self, l, r):
        return self._sum(r) - self._sum(l) BIT def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

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

     add i = i + 1 i i + 1 i 1 while i <= self.n:
            self.bit[i] += value
            i += i & -i

     i <= self.n i self.n self n self.bit[i] += value self.bit[i] self.bit self bit i value i += i & -i i i & -i i -i i self self i i value value def _sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

     _sum s = 0 s 0 while i > 0:
            s += self.bit[i]
            i -= i & -i
         i > 0 i 0 s += self.bit[i] s self.bit[i] self.bit self bit i i -= i & -i i i & -i i -i i return s s self self i i def sum(self, l, r):
        return self._sum(r) - self._sum(l) sum return self._sum(r) - self._sum(l) self._sum(r) - self._sum(l) self._sum(r) self._sum self _sum r self._sum(l) self._sum self _sum l self self l l r r n = int(input()) n int(input()) int input() input S = input() S input() input q = int(input()) q int(input()) int input() input input().split() for _ in range(q) for _ in range(q) _ range(q) range q for _ in range(q) input().split() ().split () input split Query = [input().split() for _ in range(q)] Query [input().split() for _ in range(q)] 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)] s = [] s [] for i,c in enumerate(S):
    bits[ord(c) - ord("a")].add(i,1)
    s.append(c) i c enumerate(S) enumerate S bits[ord(c) - ord("a")].add(i,1) [ord(c) - ord("a")].add [ord(c) - ord("a")] bits ord(c) - ord("a") ord(c) ord c ord("a") ord "a" add i 1 s.append(c) s.append s append c for q_type,fr,to in Query:
    if q_type == "1":
        i = int(fr)-1
        bits[ord(s[i]) - ord("a")].add(i,-1)
        bits[ord(to) - ord("a")].add(i,1)
        s[i] = to
    else:
        l,r = int(fr)-1,int(to)
        tmp = 0
        for i in range(26):
            if bits[i].sum(l,r):
                tmp += 1
        print(tmp) q_type fr to Query if q_type == "1":
        i = int(fr)-1
        bits[ord(s[i]) - ord("a")].add(i,-1)
        bits[ord(to) - ord("a")].add(i,1)
        s[i] = to
    else:
        l,r = int(fr)-1,int(to)
        tmp = 0
        for i in range(26):
            if bits[i].sum(l,r):
                tmp += 1
        print(tmp) q_type == "1" q_type "1" i = int(fr)-1 i int(fr)-1 int(fr) int fr 1 bits[ord(s[i]) - ord("a")].add(i,-1) [ord(s[i]) - ord("a")].add [ord(s[i]) - ord("a")] bits ord(s[i]) - ord("a") ord(s[i]) ord s[i] s i ord("a") ord "a" add i -1 bits[ord(to) - ord("a")].add(i,1) [ord(to) - ord("a")].add [ord(to) - ord("a")] bits ord(to) - ord("a") ord(to) ord to ord("a") ord "a" add i 1 s[i] = to s[i] s i to l,r = int(fr)-1,int(to) l int(fr)-1 int(fr) int fr 1 r int(to) int to tmp = 0 tmp 0 for i in range(26):
            if bits[i].sum(l,r):
                tmp += 1
         i range(26) range 26 if bits[i].sum(l,r):
                tmp += 1
         bits[i].sum(l,r) [i].sum [i] bits i sum l r tmp += 1 tmp 1 print(tmp) print tmp tmp += 1 1 tmp n = int(input()) int(input()) n q = int(input()) int(input()) q class BIT():
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

    def add(self, i, value):
        i = i + 1
        while i <= self.n:
            self.bit[i] += value
            i += i & -i

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

    def sum(self, l, r):
        return self._sum(r) - self._sum(l) class BIT():
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

    def add(self, i, value):
        i = i + 1
        while i <= self.n:
            self.bit[i] += value
            i += i & -i

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

    def sum(self, l, r):
        return self._sum(r) - self._sum(l) BIT r = int(fr)-1,int(to) int(to) r l,r = int(fr)-1,int(to) int(fr)-1 l tmp = 0 0 tmp Query = [input().split() for _ in range(q)] [input().split() for _ in range(q)] Query i = int(fr)-1 int(fr)-1 i S = input() input() S bits = [BIT(n) for i in range(26)] [BIT(n) for i in range(26)] bits s = [] [] s
# Binary Indexed Tree (Fenwick Tree)
class BIT():
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

    def add(self, i, value):
        i = i + 1
        while i <= self.n:
            self.bit[i] += value
            i += i & -i

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

    def sum(self, l, r):
        return self._sum(r) - self._sum(l)

n = int(input())
S = input()
q = int(input())
Query = [input().split() for _ in range(q)]

bits = [BIT(n) for i in range(26)]
s = []
for i,c in enumerate(S):
    bits[ord(c) - ord("a")].add(i,1)
    s.append(c)

for q_type,fr,to in Query:
    if q_type == "1":
        i = int(fr)-1
        bits[ord(s[i]) - ord("a")].add(i,-1)
        bits[ord(to) - ord("a")].add(i,1)
        s[i] = to
    else:
        l,r = int(fr)-1,int(to)
        tmp = 0
        for i in range(26):
            if bits[i].sum(l,r):
                tmp += 1
        print(tmp)

