import sys

input = sys.stdin.readline

class Bit:

    def __init__(self, n):

        self.size = n

        self.tree = [0] * (n + 1)

 

    def sum(self, i):

        if i == 0:

            return 0

        s = 0

        while i > 0:

            s += self.tree[i]

            i -= i & -i

        return s

 

    def add(self, i, x):

        while i <= self.size:

            self.tree[i] += x

            i += i & -i

aas = "abcdefghijklmnopqrstuvwxyz"

N = int(input().strip())

S = [" "]+list(input().strip())

Q = int(input().strip())

cbt = dict()

for c in aas:

    cbt[c] = Bit(N)

    for i, a in enumerate(S):

        if i == 0:

            continue

        if a == c:

            cbt[c].add(i, 1)



for _ in range(Q):

    t, i, c = input().split()

    t = int(t)

    if t == 1:

        i = int(i)

        if S[i] != c:

            cbt[S[i]].add(i, -1)

            cbt[c].add(i, 1)

            S[i] = c

    else:

        l, r = int(i), int(c)

        s = 0

        for a in aas:

            bt = cbt[a]

            s += (bt.sum(r)-bt.sum(l-1)>0)

        print(s)

import sys

input = sys.stdin.readline

class Bit:

    def __init__(self, n):

        self.size = n

        self.tree = [0] * (n + 1)

 

    def sum(self, i):

        s = 0

        while i > 0:       

            s += self.tree[i] 

            i -= i & -i       

        return s                            

                                            

    def add(self, i, x):                  

        while i <= self.size:

            self.tree[i] += x  

            i += i & -i

x = "abcdefghijklmnopqrstuvwxyz"

N, = list(map(int, input().split()))

d = dict()

for c in x:

    d[c] = Bit(N+1)



S = list(input().strip())

for i, c in enumerate(S):

    d[c].add(i+1, 1)



Q = int(eval(input()))

for _ in range(Q):

    t, a, b = input().split()

    if t == '1':

        i, c = int(a), b

        b = S[i-1]

        S[i-1] = c

        d[b].add(i, -1)

        d[c].add(i, 1)

    else:

        l, r = int(a), int(b)

        rr = 0

        for c in x:

            if d[c].sum(r) - d[c].sum(l-1) > 0:

                rr += 1

        print(rr)

import sys

input = sys.stdin.readline


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

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

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


aas = "abcdefghijklmnopqrstuvwxyz"
N = int(input().strip())
S = [" "] + list(input().strip())
Q = int(input().strip())
cbt = dict()
for c in aas:
    cbt[c] = Bit(N)
    for i, a in enumerate(S):
        if i == 0:
            continue
        if a == c:
            cbt[c].add(i, 1)
for _ in range(Q):
    t, i, c = input().split()
    t = int(t)
    if t == 1:
        i = int(i)
        if S[i] != c:
            cbt[S[i]].add(i, -1)
            cbt[c].add(i, 1)
            S[i] = c
    else:
        l, r = int(i), int(c)
        s = 0
        for a in aas:
            bt = cbt[a]
            s += bt.sum(r) - bt.sum(l - 1) > 0
        print(s)

import sys

input = sys.stdin.readline


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

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

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


x = "abcdefghijklmnopqrstuvwxyz"
(N,) = list(map(int, input().split()))
d = dict()
for c in x:
    d[c] = Bit(N + 1)
S = list(input().strip())
for i, c in enumerate(S):
    d[c].add(i + 1, 1)
Q = int(eval(input()))
for _ in range(Q):
    t, a, b = input().split()
    if t == "1":
        i, c = int(a), b
        b = S[i - 1]
        S[i - 1] = c
        d[b].add(i, -1)
        d[c].add(i, 1)
    else:
        l, r = int(a), int(b)
        rr = 0
        for c in x:
            if d[c].sum(r) - d[c].sum(l - 1) > 0:
                rr += 1
        print(rr)

-        if i == 0: -            return 0 -aas = "abcdefghijklmnopqrstuvwxyz" -N = int(input().strip()) -S = [" "] + list(input().strip()) -Q = int(input().strip()) -cbt = dict() -for c in aas: -    cbt[c] = Bit(N) -    for i, a in enumerate(S): -        if i == 0: -            continue -        if a == c: -            cbt[c].add(i, 1) +x = "abcdefghijklmnopqrstuvwxyz" +(N,) = list(map(int, input().split())) +d = dict() +for c in x: +    d[c] = Bit(N + 1) +S = list(input().strip()) +for i, c in enumerate(S): +    d[c].add(i + 1, 1) +Q = int(eval(input())) -    t, i, c = input().split() -    t = int(t) -    if t == 1: -        i = int(i) -        if S[i] != c: -            cbt[S[i]].add(i, -1) -            cbt[c].add(i, 1) -            S[i] = c +    t, a, b = input().split() +    if t == "1": +        i, c = int(a), b +        b = S[i - 1] +        S[i - 1] = c +        d[b].add(i, -1) +        d[c].add(i, 1) -        l, r = int(i), int(c) -        s = 0 -        for a in aas: -            bt = cbt[a] -            s += bt.sum(r) - bt.sum(l - 1) > 0 -        print(s) +        l, r = int(a), int(b) +        rr = 0 +        for c in x: +            if d[c].sum(r) - d[c].sum(l - 1) > 0: +                rr += 1 +        print(rr)