import sys

input = sys.stdin.readline

N = int(input())

S = input().rstrip()

Q = int(input())

qs = [input().split() for i in range(Q)]



def ctoi(c):

    return ord(c) - ord('a')



class BinaryIndexedTree:

    def __init__(self,size):

        self.N = size

        self.bit = [0]*(size+1)

    def add(self,x,w):

        x += 1

        while x <= self.N:

            self.bit[x] += w

            x += (x & -x)

    def sum(self,x):

        x += 1

        ret = 0

        while x > 0:

            ret += self.bit[x]

            x -= (x & -x)

        return ret

bits = [BinaryIndexedTree(N) for _ in range(26)]



for i,c in enumerate(S):

    bits[ctoi(c)].add(i,1)



s = list(S)

ans = []

for a,b,c in qs:

    if a=='1':

        x = int(b)-1

        bits[ctoi(c)].add(x,1)

        bits[ctoi(s[x])].add(x,-1)

        s[x] = c

    else:

        b,c = int(b)-1,int(c)-1

        tmp = 0

        for i in range(26):

            if bits[i].sum(c) - bits[i].sum(b-1) > 0:

                tmp += 1

        ans.append(tmp)

print(*ans, sep='\n')

import sys

input = sys.stdin.readline

N = int(input())

S = input().rstrip()

Q = int(input())

qs = [input().split() for i in range(Q)]



def ctoi(c):

    return ord(c) - ord('a')



class BinaryIndexedTree:

    def __init__(self,size):

        self.N = size

        self.bit = [0]*(size+1)

    def add(self,x,w):

        x += 1

        while x <= self.N:

            self.bit[x] += w

            x += (x & -x)

    def _sum(self,x):

        x += 1

        ret = 0

        while x > 0:

            ret += self.bit[x]

            x -= (x & -x)

        return ret

    def sum(self,l,r):

        return self._sum(r-1) - self._sum(l-1)

bits = [BinaryIndexedTree(N) for _ in range(26)]



for i,c in enumerate(S):

    bits[ctoi(c)].add(i,1)



s = list(S)

ans = []

for a,b,c in qs:

    if a=='1':

        x = int(b)-1

        bits[ctoi(c)].add(x,1)

        bits[ctoi(s[x])].add(x,-1)

        s[x] = c

    else:

        b,c = int(b)-1,int(c)

        tmp = 0

        for i in range(26):

            if bits[i].sum(b,c) > 0:

                tmp += 1

        ans.append(tmp)

print(*ans, sep='\n')

import sys

input = sys.stdin.readline
N = int(input())
S = input().rstrip()
Q = int(input())
qs = [input().split() for i in range(Q)]


def ctoi(c):
    return ord(c) - ord("a")


class BinaryIndexedTree:
    def __init__(self, size):
        self.N = size
        self.bit = [0] * (size + 1)

    def add(self, x, w):
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += x & -x

    def sum(self, x):
        x += 1
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= x & -x
        return ret


bits = [BinaryIndexedTree(N) for _ in range(26)]
for i, c in enumerate(S):
    bits[ctoi(c)].add(i, 1)
s = list(S)
ans = []
for a, b, c in qs:
    if a == "1":
        x = int(b) - 1
        bits[ctoi(c)].add(x, 1)
        bits[ctoi(s[x])].add(x, -1)
        s[x] = c
    else:
        b, c = int(b) - 1, int(c) - 1
        tmp = 0
        for i in range(26):
            if bits[i].sum(c) - bits[i].sum(b - 1) > 0:
                tmp += 1
        ans.append(tmp)
print(*ans, sep="\n")

import sys

input = sys.stdin.readline
N = int(input())
S = input().rstrip()
Q = int(input())
qs = [input().split() for i in range(Q)]


def ctoi(c):
    return ord(c) - ord("a")


class BinaryIndexedTree:
    def __init__(self, size):
        self.N = size
        self.bit = [0] * (size + 1)

    def add(self, x, w):
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += x & -x

    def _sum(self, x):
        x += 1
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= x & -x
        return ret

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


bits = [BinaryIndexedTree(N) for _ in range(26)]
for i, c in enumerate(S):
    bits[ctoi(c)].add(i, 1)
s = list(S)
ans = []
for a, b, c in qs:
    if a == "1":
        x = int(b) - 1
        bits[ctoi(c)].add(x, 1)
        bits[ctoi(s[x])].add(x, -1)
        s[x] = c
    else:
        b, c = int(b) - 1, int(c)
        tmp = 0
        for i in range(26):
            if bits[i].sum(b, c) > 0:
                tmp += 1
        ans.append(tmp)
print(*ans, sep="\n")

-    def sum(self, x): +    def _sum(self, x): + +    def sum(self, l, r): +        return self._sum(r - 1) - self._sum(l - 1) -        b, c = int(b) - 1, int(c) - 1 +        b, c = int(b) - 1, int(c) -            if bits[i].sum(c) - bits[i].sum(b - 1) > 0: +            if bits[i].sum(b, c) > 0: