
N = int(input())
S = [x for x in input()]
Q = int(input())

#A1 ... AnのBIT(1-indexed)
BIT = [[0] * (N + 1) for _ in range(26)]

#A1 ~ Aiまでの和 O(logN)
def BIT_query(input_BIT, idx):
    res_sum = 0
    while idx > 0:
        res_sum += input_BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(input_BIT,idx,x):
    while idx <= N:
        input_BIT[idx] += x
        idx += (idx&(-idx))
    return

for i, c in enumerate(S):
    BIT_update(BIT[ord(c)-ord('a')], i+1, 1)
  
for _ in range(Q):
    a, b, c = input().rstrip().split()
    if int(a) == 1:
        BIT_update(BIT[ord(S[int(b)-1])-ord('a')], int(b), -1)
        BIT_update(BIT[ord(c)-ord('a')], int(b), 1)
        S[int(b)-1] = c
    else:
        count = 0
        for i in range(26):
            if BIT_query(BIT[i], int(b)-1) != BIT_query(BIT[i], int(c)):
                count += 1
        print(count) N = int(input()) N int(input()) int input() input x for x in input() for x in input() x input() input for x in input() x S = [x for x in input()] S [x for x in input()] Q = int(input()) Q int(input()) int input() input [0] * (N + 1) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [0] * (N + 1) [0] 0 N + 1 N 1 BIT = [[0] * (N + 1) for _ in range(26)] BIT [[0] * (N + 1) for _ in range(26)] def BIT_query(input_BIT, idx):
    res_sum = 0
    while idx > 0:
        res_sum += input_BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN) BIT_query res_sum = 0 res_sum 0 while idx > 0:
        res_sum += input_BIT[idx]
        idx -= idx&(-idx)
     idx > 0 idx 0 res_sum += input_BIT[idx] res_sum input_BIT[idx] input_BIT idx idx -= idx&(-idx) idx idx&(-idx) idx -idx idx return res_sum res_sum input_BIT input_BIT idx idx def BIT_update(input_BIT,idx,x):
    while idx <= N:
        input_BIT[idx] += x
        idx += (idx&(-idx))
    return BIT_update while idx <= N:
        input_BIT[idx] += x
        idx += (idx&(-idx))
     idx <= N idx N input_BIT[idx] += x input_BIT[idx] input_BIT idx x idx += (idx&(-idx)) idx idx&(-idx) idx -idx idx return input_BIT input_BIT idx idx x x for i, c in enumerate(S):
    BIT_update(BIT[ord(c)-ord('a')], i+1, 1)
   i c enumerate(S) enumerate S BIT_update(BIT[ord(c)-ord('a')], i+1, 1) BIT_update BIT[ord(c)-ord('a')] BIT ord(c)-ord('a') ord(c) ord c ord('a') ord 'a' i+1 i 1 1 for _ in range(Q):
    a, b, c = input().rstrip().split()
    if int(a) == 1:
        BIT_update(BIT[ord(S[int(b)-1])-ord('a')], int(b), -1)
        BIT_update(BIT[ord(c)-ord('a')], int(b), 1)
        S[int(b)-1] = c
    else:
        count = 0
        for i in range(26):
            if BIT_query(BIT[i], int(b)-1) != BIT_query(BIT[i], int(c)):
                count += 1
        print(count) _ range(Q) range Q a, b, c = input().rstrip().split() a input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split b c if int(a) == 1:
        BIT_update(BIT[ord(S[int(b)-1])-ord('a')], int(b), -1)
        BIT_update(BIT[ord(c)-ord('a')], int(b), 1)
        S[int(b)-1] = c
    else:
        count = 0
        for i in range(26):
            if BIT_query(BIT[i], int(b)-1) != BIT_query(BIT[i], int(c)):
                count += 1
        print(count) int(a) == 1 int(a) int a 1 BIT_update(BIT[ord(S[int(b)-1])-ord('a')], int(b), -1) BIT_update BIT[ord(S[int(b)-1])-ord('a')] BIT ord(S[int(b)-1])-ord('a') ord(S[int(b)-1]) ord S[int(b)-1] S int(b)-1 int(b) int b 1 ord('a') ord 'a' int(b) int b -1 BIT_update(BIT[ord(c)-ord('a')], int(b), 1) BIT_update BIT[ord(c)-ord('a')] BIT ord(c)-ord('a') ord(c) ord c ord('a') ord 'a' int(b) int b 1 S[int(b)-1] = c S[int(b)-1] S int(b)-1 int(b) int b 1 c count = 0 count 0 for i in range(26):
            if BIT_query(BIT[i], int(b)-1) != BIT_query(BIT[i], int(c)):
                count += 1
         i range(26) range 26 if BIT_query(BIT[i], int(b)-1) != BIT_query(BIT[i], int(c)):
                count += 1
         BIT_query(BIT[i], int(b)-1) != BIT_query(BIT[i], int(c)) BIT_query(BIT[i], int(b)-1) BIT_query BIT[i] BIT i int(b)-1 int(b) int b 1 BIT_query(BIT[i], int(c)) BIT_query BIT[i] BIT i int(c) int c count += 1 count 1 print(count) print count b, c = input().rstrip().split() input().rstrip().split() b a, b, c = input().rstrip().split() input().rstrip().split() a count = 0 0 count Q = int(input()) int(input()) Q def BIT_query(input_BIT, idx):
    res_sum = 0
    while idx > 0:
        res_sum += input_BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN) def BIT_query(input_BIT, idx):
    res_sum = 0
    while idx > 0:
        res_sum += input_BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN) BIT_query def BIT_update(input_BIT,idx,x):
    while idx <= N:
        input_BIT[idx] += x
        idx += (idx&(-idx))
    return def BIT_update(input_BIT,idx,x):
    while idx <= N:
        input_BIT[idx] += x
        idx += (idx&(-idx))
    return BIT_update count += 1 1 count N = int(input()) int(input()) N S = [x for x in input()] [x for x in input()] S BIT = [[0] * (N + 1) for _ in range(26)] [[0] * (N + 1) for _ in range(26)] BIT c = input().rstrip().split() input().rstrip().split() c

N = int(input())
S = [x for x in input()]
Q = int(input())

#A1 ... AnのBIT(1-indexed)
BIT = [[0] * (N + 1) for _ in range(26)]

#A1 ~ Aiまでの和 O(logN)
def BIT_query(input_BIT, idx):
    res_sum = 0
    while idx > 0:
        res_sum += input_BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(input_BIT,idx,x):
    while idx <= N:
        input_BIT[idx] += x
        idx += (idx&(-idx))
    return

for i, c in enumerate(S):
    BIT_update(BIT[ord(c)-ord('a')], i+1, 1)
  
for _ in range(Q):
    a, b, c = input().rstrip().split()
    if int(a) == 1:
        BIT_update(BIT[ord(S[int(b)-1])-ord('a')], int(b), -1)
        BIT_update(BIT[ord(c)-ord('a')], int(b), 1)
        S[int(b)-1] = c
    else:
        count = 0
        for i in range(26):
            if BIT_query(BIT[i], int(b)-1) != BIT_query(BIT[i], int(c)):
                count += 1
        print(count)