#####segfunc######
def segfunc(x,y):
    return x + y

def init(init_val,j):
    #set_val
    for i in range(n):
        seg[j][i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[j][i]=segfunc(seg[j][2*i+1],seg[j][2*i+2]) 
    
def update(k,x,j):
    k += num-1
    seg[j][k] = x
    while k:
        k = (k-1)//2
        seg[j][k] = segfunc(seg[j][k*2+1],seg[j][k*2+2])
    
def query(p,q,j):
    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[j][p])
        if q&1 == 1:
            res = segfunc(res,seg[j][q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[j][p])
    else:
        res = segfunc(segfunc(res,seg[j][p]),seg[j][q])
    return res


n = int(input())
s = list(input())
q = int(input())
al = []
l = [[0 for i in range(n)] for i in range(26)]
for i in range(n):
    l[ord(s[i])-97][i] = 1
seg = [[] for i in range(26)]
for i in range(26):
#####単位元######
    ide_ele = 0
#num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    seg[i]=[ide_ele]*2*num
    init(l[i],i)
for i in range(q):
    q1 = list(input().split())
    if q1[0] == "1":
        p = int(q1[1])
        r = ord(q1[2]) - 97
        for j in range(26):
            if l[j][p-1] == 1 and j != r:
                update(p-1,0,j)
            elif j == r:
                update(p-1,1,j)
            else:
                update(p-1,0,j)
    else:
        a = int(q1[1])
        b = int(q1[2])
        #print(a,b,seg)
        aa = 0
        for j in range(26):
            if query(a-1,b,j) > 0:
                aa += 1
        al.append(aa)
for i in al:
    print(i) def segfunc(x,y):
    return x + y segfunc return x + y x + y x y x x y y def init(init_val,j):
    #set_val
    for i in range(n):
        seg[j][i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[j][i]=segfunc(seg[j][2*i+1],seg[j][2*i+2]) 
     init for i in range(n):
        seg[j][i+num-1]=init_val[i]    
    #built
     i range(n) range n seg[j][i+num-1]=init_val[i] seg[j][i+num-1] [j] seg j i+num-1 i+num i num 1 init_val[i] init_val i for i in range(num-2,-1,-1) :
        seg[j][i]=segfunc(seg[j][2*i+1],seg[j][2*i+2]) 
     i range(num-2,-1,-1) range num-2 num 2 -1 -1 seg[j][i]=segfunc(seg[j][2*i+1],seg[j][2*i+2]) seg[j][i] [j] seg j i segfunc(seg[j][2*i+1],seg[j][2*i+2]) segfunc seg[j][2*i+1] [j] seg j 2*i+1 2*i 2 i 1 seg[j][2*i+2] [j] seg j 2*i+2 2*i 2 i 2 init_val init_val j j def update(k,x,j):
    k += num-1
    seg[j][k] = x
    while k:
        k = (k-1)//2
        seg[j][k] = segfunc(seg[j][k*2+1],seg[j][k*2+2])
     update k += num-1 k num-1 num 1 seg[j][k] = x seg[j][k] [j] seg j k x while k:
        k = (k-1)//2
        seg[j][k] = segfunc(seg[j][k*2+1],seg[j][k*2+2])
     k k = (k-1)//2 k (k-1)//2 k-1 k 1 2 seg[j][k] = segfunc(seg[j][k*2+1],seg[j][k*2+2]) seg[j][k] [j] seg j k segfunc(seg[j][k*2+1],seg[j][k*2+2]) segfunc seg[j][k*2+1] [j] seg j k*2+1 k*2 k 2 1 seg[j][k*2+2] [j] seg j k*2+2 k*2 k 2 2 k k x x j j def query(p,q,j):
    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[j][p])
        if q&1 == 1:
            res = segfunc(res,seg[j][q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[j][p])
    else:
        res = segfunc(segfunc(res,seg[j][p]),seg[j][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[j][p])
        if q&1 == 1:
            res = segfunc(res,seg[j][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[j][p])
         p&1 == 0 p&1 p 1 0 res = segfunc(res,seg[j][p]) res segfunc(res,seg[j][p]) segfunc res seg[j][p] [j] seg j p if q&1 == 1:
            res = segfunc(res,seg[j][q])
            q -= 1
         q&1 == 1 q&1 q 1 1 res = segfunc(res,seg[j][q]) res segfunc(res,seg[j][q]) segfunc res seg[j][q] [j] seg j 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[j][p])
    else:
        res = segfunc(segfunc(res,seg[j][p]),seg[j][q])
     p == q p q res = segfunc(res,seg[j][p]) res segfunc(res,seg[j][p]) segfunc res seg[j][p] [j] seg j p res = segfunc(segfunc(res,seg[j][p]),seg[j][q]) res segfunc(segfunc(res,seg[j][p]),seg[j][q]) segfunc segfunc(res,seg[j][p]) segfunc res seg[j][p] [j] seg j p seg[j][q] [j] seg j q return res res p p q q j j n = int(input()) n int(input()) int input() input s = list(input()) s list(input()) list input() input q = int(input()) q int(input()) int input() input al = [] al [] [0 for i in range(n)] for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) [0 for i in range(n)] l = [[0 for i in range(n)] for i in range(26)] l [[0 for i in range(n)] for i in range(26)] for i in range(n):
    l[ord(s[i])-97][i] = 1 i range(n) range n l[ord(s[i])-97][i] = 1 l[ord(s[i])-97][i] [ord(s[i])-97] l ord(s[i])-97 ord(s[i]) ord s[i] s i 97 i 1 [] for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) [] seg = [[] for i in range(26)] seg [[] for i in range(26)] for i in range(26):
#####単位元######
    ide_ele = 0
#num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    seg[i]=[ide_ele]*2*num
    init(l[i],i) i range(26) range 26 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[i]=[ide_ele]*2*num seg[i] seg i [ide_ele]*2*num [ide_ele]*2 [ide_ele] ide_ele 2 num init(l[i],i) init l[i] l i i for i in range(q):
    q1 = list(input().split())
    if q1[0] == "1":
        p = int(q1[1])
        r = ord(q1[2]) - 97
        for j in range(26):
            if l[j][p-1] == 1 and j != r:
                update(p-1,0,j)
            elif j == r:
                update(p-1,1,j)
            else:
                update(p-1,0,j)
    else:
        a = int(q1[1])
        b = int(q1[2])
        #print(a,b,seg)
        aa = 0
        for j in range(26):
            if query(a-1,b,j) > 0:
                aa += 1
        al.append(aa) i range(q) range q q1 = list(input().split()) q1 list(input().split()) list input().split() ().split () input split if q1[0] == "1":
        p = int(q1[1])
        r = ord(q1[2]) - 97
        for j in range(26):
            if l[j][p-1] == 1 and j != r:
                update(p-1,0,j)
            elif j == r:
                update(p-1,1,j)
            else:
                update(p-1,0,j)
    else:
        a = int(q1[1])
        b = int(q1[2])
        #print(a,b,seg)
        aa = 0
        for j in range(26):
            if query(a-1,b,j) > 0:
                aa += 1
        al.append(aa) q1[0] == "1" q1[0] q1 0 "1" p = int(q1[1]) p int(q1[1]) int q1[1] q1 1 r = ord(q1[2]) - 97 r ord(q1[2]) - 97 ord(q1[2]) ord q1[2] q1 2 97 for j in range(26):
            if l[j][p-1] == 1 and j != r:
                update(p-1,0,j)
            elif j == r:
                update(p-1,1,j)
            else:
                update(p-1,0,j)
     j range(26) range 26 if l[j][p-1] == 1 and j != r:
                update(p-1,0,j)
            elif j == r:
                update(p-1,1,j)
            else:
                update(p-1,0,j)
     l[j][p-1] == 1 and j != r l[j][p-1] == 1 l[j][p-1] [j] l j p-1 p 1 1 j != r j r update(p-1,0,j) update p-1 p 1 0 j elif j == r:
                update(p-1,1,j)
             j == r j r update(p-1,1,j) update p-1 p 1 1 j update(p-1,0,j) update p-1 p 1 0 j a = int(q1[1]) a int(q1[1]) int q1[1] q1 1 b = int(q1[2]) b int(q1[2]) int q1[2] q1 2 aa = 0 aa 0 for j in range(26):
            if query(a-1,b,j) > 0:
                aa += 1
         j range(26) range 26 if query(a-1,b,j) > 0:
                aa += 1
         query(a-1,b,j) > 0 query(a-1,b,j) query a-1 a 1 b j 0 aa += 1 aa 1 al.append(aa) al.append al append aa for i in al:
    print(i) i al print(i) print i al = [] [] al l = [[0 for i in range(n)] for i in range(26)] [[0 for i in range(n)] for i in range(26)] l def query(p,q,j):
    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[j][p])
        if q&1 == 1:
            res = segfunc(res,seg[j][q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[j][p])
    else:
        res = segfunc(segfunc(res,seg[j][p]),seg[j][q])
    return res def query(p,q,j):
    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[j][p])
        if q&1 == 1:
            res = segfunc(res,seg[j][q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[j][p])
    else:
        res = segfunc(segfunc(res,seg[j][p]),seg[j][q])
    return res query num =2**(n-1).bit_length() 2**(n-1).bit_length() num r = ord(q1[2]) - 97 ord(q1[2]) - 97 r q = int(input()) int(input()) q b = int(q1[2]) int(q1[2]) b s = list(input()) list(input()) s aa = 0 0 aa n = int(input()) int(input()) n aa += 1 1 aa def init(init_val,j):
    #set_val
    for i in range(n):
        seg[j][i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[j][i]=segfunc(seg[j][2*i+1],seg[j][2*i+2]) 
     def init(init_val,j):
    #set_val
    for i in range(n):
        seg[j][i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[j][i]=segfunc(seg[j][2*i+1],seg[j][2*i+2]) 
     init def segfunc(x,y):
    return x + y def segfunc(x,y):
    return x + y segfunc p = int(q1[1]) int(q1[1]) p a = int(q1[1]) int(q1[1]) a q1 = list(input().split()) list(input().split()) q1 ide_ele = 0 0 ide_ele def update(k,x,j):
    k += num-1
    seg[j][k] = x
    while k:
        k = (k-1)//2
        seg[j][k] = segfunc(seg[j][k*2+1],seg[j][k*2+2])
     def update(k,x,j):
    k += num-1
    seg[j][k] = x
    while k:
        k = (k-1)//2
        seg[j][k] = segfunc(seg[j][k*2+1],seg[j][k*2+2])
     update seg = [[] for i in range(26)] [[] for i in range(26)] seg
#####segfunc######
def segfunc(x,y):
    return x + y

def init(init_val,j):
    #set_val
    for i in range(n):
        seg[j][i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[j][i]=segfunc(seg[j][2*i+1],seg[j][2*i+2]) 
    
def update(k,x,j):
    k += num-1
    seg[j][k] = x
    while k:
        k = (k-1)//2
        seg[j][k] = segfunc(seg[j][k*2+1],seg[j][k*2+2])
    
def query(p,q,j):
    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[j][p])
        if q&1 == 1:
            res = segfunc(res,seg[j][q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[j][p])
    else:
        res = segfunc(segfunc(res,seg[j][p]),seg[j][q])
    return res


n = int(input())
s = list(input())
q = int(input())
al = []
l = [[0 for i in range(n)] for i in range(26)]
for i in range(n):
    l[ord(s[i])-97][i] = 1
seg = [[] for i in range(26)]
for i in range(26):
#####単位元######
    ide_ele = 0
#num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    seg[i]=[ide_ele]*2*num
    init(l[i],i)
for i in range(q):
    q1 = list(input().split())
    if q1[0] == "1":
        p = int(q1[1])
        r = ord(q1[2]) - 97
        for j in range(26):
            if l[j][p-1] == 1 and j != r:
                update(p-1,0,j)
            elif j == r:
                update(p-1,1,j)
            else:
                update(p-1,0,j)
    else:
        a = int(q1[1])
        b = int(q1[2])
        #print(a,b,seg)
        aa = 0
        for j in range(26):
            if query(a-1,b,j) > 0:
                aa += 1
        al.append(aa)
for i in al:
    print(i)