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

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


alps = 'abcdefghijklmnopqrstuvwxyz'

n = int(input())
s = list(input())
char_hd_d = {}
for alp in alps:
    char_hd_d[alp] = [0]*(n+1)

for i, si in enumerate(s):
    BIT_update(char_hd_d[si], i+1, 1)

q = int(input())
ansl = []
for _ in range(q):
    command, a, b = input().split()
    if command == '1':
        i = int(a)
        c = b
        i_char = s[i-1]
        BIT_update(char_hd_d[i_char], i, -1)
        BIT_update(char_hd_d[c], i, 1)
        s[i-1] = c 
    else:
        l,r = int(a),int(b)
        cnt = 0
        for alp in alps:
            if BIT_query(char_hd_d[alp], r) - BIT_query(char_hd_d[alp], l-1) > 0:
                cnt += 1
        ansl.append(cnt)

for a in ansl:
    print(a)             def BIT_query(BIT,idx):
    res_sum = 0
    while idx > 0:
        res_sum += 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 += BIT[idx]
        idx -= idx&(-idx)
     idx > 0 idx 0 res_sum += BIT[idx] res_sum BIT[idx] BIT idx idx -= idx&(-idx) idx idx&(-idx) idx -idx idx return res_sum res_sum BIT BIT idx idx def BIT_update(BIT,idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return BIT_update while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
     idx <= n idx n BIT[idx] += x BIT[idx] BIT idx x idx += idx&(-idx) idx idx&(-idx) idx -idx idx return BIT BIT idx idx x x alps = 'abcdefghijklmnopqrstuvwxyz' alps 'abcdefghijklmnopqrstuvwxyz' n = int(input()) n int(input()) int input() input s = list(input()) s list(input()) list input() input char_hd_d = {} char_hd_d {} for alp in alps:
    char_hd_d[alp] = [0]*(n+1) alp alps char_hd_d[alp] = [0]*(n+1) char_hd_d[alp] char_hd_d alp [0]*(n+1) [0] 0 n+1 n 1 for i, si in enumerate(s):
    BIT_update(char_hd_d[si], i+1, 1) i si enumerate(s) enumerate s BIT_update(char_hd_d[si], i+1, 1) BIT_update char_hd_d[si] char_hd_d si i+1 i 1 1 q = int(input()) q int(input()) int input() input ansl = [] ansl [] for _ in range(q):
    command, a, b = input().split()
    if command == '1':
        i = int(a)
        c = b
        i_char = s[i-1]
        BIT_update(char_hd_d[i_char], i, -1)
        BIT_update(char_hd_d[c], i, 1)
        s[i-1] = c 
    else:
        l,r = int(a),int(b)
        cnt = 0
        for alp in alps:
            if BIT_query(char_hd_d[alp], r) - BIT_query(char_hd_d[alp], l-1) > 0:
                cnt += 1
        ansl.append(cnt) _ range(q) range q command, a, b = input().split() command input().split() ().split () input split a b if command == '1':
        i = int(a)
        c = b
        i_char = s[i-1]
        BIT_update(char_hd_d[i_char], i, -1)
        BIT_update(char_hd_d[c], i, 1)
        s[i-1] = c 
    else:
        l,r = int(a),int(b)
        cnt = 0
        for alp in alps:
            if BIT_query(char_hd_d[alp], r) - BIT_query(char_hd_d[alp], l-1) > 0:
                cnt += 1
        ansl.append(cnt) command == '1' command '1' i = int(a) i int(a) int a c = b c b i_char = s[i-1] i_char s[i-1] s i-1 i 1 BIT_update(char_hd_d[i_char], i, -1) BIT_update char_hd_d[i_char] char_hd_d i_char i -1 BIT_update(char_hd_d[c], i, 1) BIT_update char_hd_d[c] char_hd_d c i 1 s[i-1] = c s[i-1] s i-1 i 1 c l,r = int(a),int(b) l int(a) int a r int(b) int b cnt = 0 cnt 0 for alp in alps:
            if BIT_query(char_hd_d[alp], r) - BIT_query(char_hd_d[alp], l-1) > 0:
                cnt += 1
         alp alps if BIT_query(char_hd_d[alp], r) - BIT_query(char_hd_d[alp], l-1) > 0:
                cnt += 1
         BIT_query(char_hd_d[alp], r) - BIT_query(char_hd_d[alp], l-1) > 0 BIT_query(char_hd_d[alp], r) - BIT_query(char_hd_d[alp], l-1) BIT_query(char_hd_d[alp], r) BIT_query char_hd_d[alp] char_hd_d alp r BIT_query(char_hd_d[alp], l-1) BIT_query char_hd_d[alp] char_hd_d alp l-1 l 1 0 cnt += 1 cnt 1 ansl.append(cnt) ansl.append ansl append cnt for a in ansl:
    print(a)             a ansl print(a) print a def BIT_query(BIT,idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

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

#Ai += x O(logN) BIT_query s = list(input()) list(input()) s i = int(a) int(a) i l,r = int(a),int(b) int(a) l a, b = input().split() input().split() a ansl = [] [] ansl i_char = s[i-1] s[i-1] i_char q = int(input()) int(input()) q n = int(input()) int(input()) n alps = 'abcdefghijklmnopqrstuvwxyz' 'abcdefghijklmnopqrstuvwxyz' alps c = b b c command, a, b = input().split() input().split() command cnt = 0 0 cnt cnt += 1 1 cnt r = int(a),int(b) int(b) r b = input().split() input().split() b char_hd_d = {} {} char_hd_d def BIT_update(BIT,idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return def BIT_update(BIT,idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return BIT_update
#A1 ~ Aiまでの和 O(logN)
def BIT_query(BIT,idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

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


alps = 'abcdefghijklmnopqrstuvwxyz'

n = int(input())
s = list(input())
char_hd_d = {}
for alp in alps:
    char_hd_d[alp] = [0]*(n+1)

for i, si in enumerate(s):
    BIT_update(char_hd_d[si], i+1, 1)

q = int(input())
ansl = []
for _ in range(q):
    command, a, b = input().split()
    if command == '1':
        i = int(a)
        c = b
        i_char = s[i-1]
        BIT_update(char_hd_d[i_char], i, -1)
        BIT_update(char_hd_d[c], i, 1)
        s[i-1] = c 
    else:
        l,r = int(a),int(b)
        cnt = 0
        for alp in alps:
            if BIT_query(char_hd_d[alp], r) - BIT_query(char_hd_d[alp], l-1) > 0:
                cnt += 1
        ansl.append(cnt)

for a in ansl:
    print(a)            