import sys
input = sys.stdin.readline

def segfunc(x,y):
    return x | y

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res


n = int(input())
s = input()
q = int(input())

li = []
for i in range(n):
    li.append(1 << ord(s[i]) - ord('a'))

#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
init(li)

for _ in range(q):
    q1 = list(input().split())
    if q1[0] == '1':
        update(int(q1[1]) - 1, 1 << ord(q1[2]) - ord('a'))
    else:
        l,r = int(q1[1]), int(q1[2])
        print(bin(query(l-1,r)).count('1')) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def segfunc(x,y):
    return x | y segfunc return x | y x | y x y x x y y def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) init for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
     i range(n) range n seg[i+num-1]=init_val[i] seg[i+num-1] seg i+num-1 i+num i num 1 init_val[i] init_val i for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) i range(num-2,-1,-1) range num-2 num 2 -1 -1 seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) seg[i] seg i segfunc(seg[2*i+1],seg[2*i+2]) segfunc seg[2*i+1] seg 2*i+1 2*i 2 i 1 seg[2*i+2] seg 2*i+2 2*i 2 i 2 init_val init_val def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2]) update k += num-1 k num-1 num 1 seg[k] = x seg[k] seg k x while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2]) k k = (k-1)//2 k (k-1)//2 k-1 k 1 2 seg[k] = segfunc(seg[k*2+1],seg[k*2+2]) seg[k] seg k segfunc(seg[k*2+1],seg[k*2+2]) segfunc seg[k*2+1] seg k*2+1 k*2 k 2 1 seg[k*2+2] seg k*2+2 k*2 k 2 2 k k x x def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res query if q<=p:
        return ide_ele
     q<=p q p return ide_ele ide_ele p += num-1 p num-1 num 1 q += num-2 q num-2 num 2 res=ide_ele res ide_ele while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
     q-p>1 q-p q p 1 if p&1 == 0:
            res = segfunc(res,seg[p])
         p&1 == 0 p&1 p 1 0 res = segfunc(res,seg[p]) res segfunc(res,seg[p]) segfunc res seg[p] seg p if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
         q&1 == 1 q&1 q 1 1 res = segfunc(res,seg[q]) res segfunc(res,seg[q]) segfunc res seg[q] seg q q -= 1 q 1 p = p//2 p p//2 p 2 q = (q-1)//2 q (q-1)//2 q-1 q 1 2 if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
     p == q p q res = segfunc(res,seg[p]) res segfunc(res,seg[p]) segfunc res seg[p] seg p res = segfunc(segfunc(res,seg[p]),seg[q]) res segfunc(segfunc(res,seg[p]),seg[q]) segfunc segfunc(res,seg[p]) segfunc res seg[p] seg p seg[q] seg q return res res p p q q n = int(input()) n int(input()) int input() input s = input() s input() input q = int(input()) q int(input()) int input() input li = [] li [] for i in range(n):
    li.append(1 << ord(s[i]) - ord('a'))

#####単位元###### i range(n) range n li.append(1 << ord(s[i]) - ord('a')) li.append li append 1 << ord(s[i]) - ord('a') 1 ord(s[i]) - ord('a') ord(s[i]) ord s[i] s i ord('a') ord 'a' ide_ele = 0 ide_ele 0 num =2**(n-1).bit_length() num 2**(n-1).bit_length() 2 (n-1).bit_length() n-1).bit_length n-1 n 1 bit_length seg=[ide_ele]*2*num seg [ide_ele]*2*num [ide_ele]*2 [ide_ele] ide_ele 2 num init(li) init li for _ in range(q):
    q1 = list(input().split())
    if q1[0] == '1':
        update(int(q1[1]) - 1, 1 << ord(q1[2]) - ord('a'))
    else:
        l,r = int(q1[1]), int(q1[2])
        print(bin(query(l-1,r)).count('1')) _ range(q) range q q1 = list(input().split()) q1 list(input().split()) list input().split() ().split () input split if q1[0] == '1':
        update(int(q1[1]) - 1, 1 << ord(q1[2]) - ord('a'))
    else:
        l,r = int(q1[1]), int(q1[2])
        print(bin(query(l-1,r)).count('1')) q1[0] == '1' q1[0] q1 0 '1' update(int(q1[1]) - 1, 1 << ord(q1[2]) - ord('a')) update int(q1[1]) - 1 int(q1[1]) int q1[1] q1 1 1 1 << ord(q1[2]) - ord('a') 1 ord(q1[2]) - ord('a') ord(q1[2]) ord q1[2] q1 2 ord('a') ord 'a' l,r = int(q1[1]), int(q1[2]) l int(q1[1]) int q1[1] q1 1 r int(q1[2]) int q1[2] q1 2 print(bin(query(l-1,r)).count('1')) print bin(query(l-1,r)).count('1') (query(l-1,r)).count (query(l-1,r)) bin query(l-1,r) query l-1 l 1 r count '1' def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res query input = sys.stdin.readline sys.stdin.readline input def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) init def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2]) def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2]) update l,r = int(q1[1]), int(q1[2]) int(q1[1]) l q1 = list(input().split()) list(input().split()) q1 n = int(input()) int(input()) n ide_ele = 0 0 ide_ele r = int(q1[1]), int(q1[2]) int(q1[2]) r seg=[ide_ele]*2*num [ide_ele]*2*num seg q = int(input()) int(input()) q def segfunc(x,y):
    return x | y def segfunc(x,y):
    return x | y segfunc num =2**(n-1).bit_length() 2**(n-1).bit_length() num s = input() input() s li = [] [] li
import sys
input = sys.stdin.readline

def segfunc(x,y):
    return x | y

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res


n = int(input())
s = input()
q = int(input())

li = []
for i in range(n):
    li.append(1 << ord(s[i]) - ord('a'))

#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
init(li)

for _ in range(q):
    q1 = list(input().split())
    if q1[0] == '1':
        update(int(q1[1]) - 1, 1 << ord(q1[2]) - ord('a'))
    else:
        l,r = int(q1[1]), int(q1[2])
        print(bin(query(l-1,r)).count('1'))
