import copy

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


def update(k, cs):
    ls = s[k]
    if ls == cs:
        return
    k += num-1
    seg[cs][k] = 1
    seg[ls][k] = 0
    while k:
        k = (k-1)//2
        seg[ls][k] = seg[ls][k*2+1] | seg[ls][k*2+2]
        seg[cs][k] = seg[cs][k*2+1] | seg[cs][k*2+2]


def query(pp, qq): # pからq-1までの最大値
    pp += num-1
    qq += num-2
    total = 0
    for j in range(26):
        p = copy.deepcopy(pp)
        q = copy.deepcopy(qq)
        res = 0
        while q - p > 1:
            if res == 1:
                break
            if p&1 == 0:
                res = res | seg[j][p]
            if q&1 == 1:
                res = res | seg[j][q]
                q -= 1
            p = p//2
            q = (q-1)//2
        if q - p > 1:
            total += res
            continue
        if p == q:
            res = res | seg[j][p]
        else:
            res = res | seg[j][p] | seg[j][q]
        total += res
    return total


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

for i in range(n):
    s[i] = ord(s[i]) - 97
#num:n以上の最小の2のべき乗
num = 2**(n-1).bit_length()
seg = [[0]*(2*num) for i in range(26)]
init(s)
for i in range(q):
    cq = list(input().split())
    if cq[0] == '1':
        cn, cs = int(cq[1]) - 1, ord(cq[2]) - 97
        update(cn, cs)
        s[cn] = cs
    if cq[0] == '2':
        p, q = int(cq[1]) - 1, int(cq[2])
        print(query(p, q)) import copy copy def init(init_val):
    for j in range(26):
        #set_val
        for i in range(n):
            if init_val[i] == j:
                seg[j][i+num-1] = 1
        #built
        for i in range(num-2,-1,-1):
            seg[j][i] = seg[j][2*i+1] | seg[j][2*i+2] init for j in range(26):
        #set_val
        for i in range(n):
            if init_val[i] == j:
                seg[j][i+num-1] = 1
        #built
        for i in range(num-2,-1,-1):
            seg[j][i] = seg[j][2*i+1] | seg[j][2*i+2] j range(26) range 26 for i in range(n):
            if init_val[i] == j:
                seg[j][i+num-1] = 1
        #built
         i range(n) range n if init_val[i] == j:
                seg[j][i+num-1] = 1
        #built
         init_val[i] == j init_val[i] init_val i j seg[j][i+num-1] = 1 seg[j][i+num-1] [j] seg j i+num-1 i+num i num 1 1 for i in range(num-2,-1,-1):
            seg[j][i] = 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] = seg[j][2*i+1] | seg[j][2*i+2] seg[j][i] [j] seg j i seg[j][2*i+1] | seg[j][2*i+2] 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 def update(k, cs):
    ls = s[k]
    if ls == cs:
        return
    k += num-1
    seg[cs][k] = 1
    seg[ls][k] = 0
    while k:
        k = (k-1)//2
        seg[ls][k] = seg[ls][k*2+1] | seg[ls][k*2+2]
        seg[cs][k] = seg[cs][k*2+1] | seg[cs][k*2+2] update ls = s[k] ls s[k] s k if ls == cs:
        return
     ls == cs ls cs return k += num-1 k num-1 num 1 seg[cs][k] = 1 seg[cs][k] [cs] seg cs k 1 seg[ls][k] = 0 seg[ls][k] [ls] seg ls k 0 while k:
        k = (k-1)//2
        seg[ls][k] = seg[ls][k*2+1] | seg[ls][k*2+2]
        seg[cs][k] = seg[cs][k*2+1] | seg[cs][k*2+2] k k = (k-1)//2 k (k-1)//2 k-1 k 1 2 seg[ls][k] = seg[ls][k*2+1] | seg[ls][k*2+2] seg[ls][k] [ls] seg ls k seg[ls][k*2+1] | seg[ls][k*2+2] seg[ls][k*2+1] [ls] seg ls k*2+1 k*2 k 2 1 seg[ls][k*2+2] [ls] seg ls k*2+2 k*2 k 2 2 seg[cs][k] = seg[cs][k*2+1] | seg[cs][k*2+2] seg[cs][k] [cs] seg cs k seg[cs][k*2+1] | seg[cs][k*2+2] seg[cs][k*2+1] [cs] seg cs k*2+1 k*2 k 2 1 seg[cs][k*2+2] [cs] seg cs k*2+2 k*2 k 2 2 k k cs cs def query(pp, qq): # pからq-1までの最大値
    pp += num-1
    qq += num-2
    total = 0
    for j in range(26):
        p = copy.deepcopy(pp)
        q = copy.deepcopy(qq)
        res = 0
        while q - p > 1:
            if res == 1:
                break
            if p&1 == 0:
                res = res | seg[j][p]
            if q&1 == 1:
                res = res | seg[j][q]
                q -= 1
            p = p//2
            q = (q-1)//2
        if q - p > 1:
            total += res
            continue
        if p == q:
            res = res | seg[j][p]
        else:
            res = res | seg[j][p] | seg[j][q]
        total += res
    return total query pp += num-1 pp num-1 num 1 qq += num-2 qq num-2 num 2 total = 0 total 0 for j in range(26):
        p = copy.deepcopy(pp)
        q = copy.deepcopy(qq)
        res = 0
        while q - p > 1:
            if res == 1:
                break
            if p&1 == 0:
                res = res | seg[j][p]
            if q&1 == 1:
                res = res | seg[j][q]
                q -= 1
            p = p//2
            q = (q-1)//2
        if q - p > 1:
            total += res
            continue
        if p == q:
            res = res | seg[j][p]
        else:
            res = res | seg[j][p] | seg[j][q]
        total += res
     j range(26) range 26 p = copy.deepcopy(pp) p copy.deepcopy(pp) copy.deepcopy copy deepcopy pp q = copy.deepcopy(qq) q copy.deepcopy(qq) copy.deepcopy copy deepcopy qq res = 0 res 0 while q - p > 1:
            if res == 1:
                break
            if p&1 == 0:
                res = res | seg[j][p]
            if q&1 == 1:
                res = res | seg[j][q]
                q -= 1
            p = p//2
            q = (q-1)//2
         q - p > 1 q - p q p 1 if res == 1:
                break
             res == 1 res 1 break if p&1 == 0:
                res = res | seg[j][p]
             p&1 == 0 p&1 p 1 0 res = res | seg[j][p] res res | seg[j][p] res seg[j][p] [j] seg j p if q&1 == 1:
                res = res | seg[j][q]
                q -= 1
             q&1 == 1 q&1 q 1 1 res = res | seg[j][q] res res | seg[j][q] 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 q - p > 1:
            total += res
            continue
         q - p > 1 q - p q p 1 total += res total res continue if p == q:
            res = res | seg[j][p]
        else:
            res = res | seg[j][p] | seg[j][q]
         p == q p q res = res | seg[j][p] res res | seg[j][p] res seg[j][p] [j] seg j p res = res | seg[j][p] | seg[j][q] res res | seg[j][p] | seg[j][q] res | seg[j][p] res seg[j][p] [j] seg j p seg[j][q] [j] seg j q total += res total res return total total pp pp qq qq 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 for i in range(n):
    s[i] = ord(s[i]) - 97
#num:n以上の最小の2のべき乗 i range(n) range n s[i] = ord(s[i]) - 97 s[i] s i ord(s[i]) - 97 ord(s[i]) ord s[i] s i 97 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 [0]*(2*num) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) [0]*(2*num) [0] 0 2*num 2 num seg = [[0]*(2*num) for i in range(26)] seg [[0]*(2*num) for i in range(26)] init(s) init s for i in range(q):
    cq = list(input().split())
    if cq[0] == '1':
        cn, cs = int(cq[1]) - 1, ord(cq[2]) - 97
        update(cn, cs)
        s[cn] = cs
    if cq[0] == '2':
        p, q = int(cq[1]) - 1, int(cq[2])
        print(query(p, q)) i range(q) range q cq = list(input().split()) cq list(input().split()) list input().split() ().split () input split if cq[0] == '1':
        cn, cs = int(cq[1]) - 1, ord(cq[2]) - 97
        update(cn, cs)
        s[cn] = cs
     cq[0] == '1' cq[0] cq 0 '1' cn, cs = int(cq[1]) - 1, ord(cq[2]) - 97 cn int(cq[1]) - 1 int(cq[1]) int cq[1] cq 1 1 cs ord(cq[2]) - 97 ord(cq[2]) ord cq[2] cq 2 97 update(cn, cs) update cn cs s[cn] = cs s[cn] s cn cs if cq[0] == '2':
        p, q = int(cq[1]) - 1, int(cq[2])
        print(query(p, q)) cq[0] == '2' cq[0] cq 0 '2' p, q = int(cq[1]) - 1, int(cq[2]) p int(cq[1]) - 1 int(cq[1]) int cq[1] cq 1 1 q int(cq[2]) int cq[2] cq 2 print(query(p, q)) print query(p, q) query p q n = int(input()) int(input()) n cq = list(input().split()) list(input().split()) cq seg = [[0]*(2*num) for i in range(26)] [[0]*(2*num) for i in range(26)] seg q = int(cq[1]) - 1, int(cq[2]) int(cq[2]) q cs = int(cq[1]) - 1, ord(cq[2]) - 97 ord(cq[2]) - 97 cs def update(k, cs):
    ls = s[k]
    if ls == cs:
        return
    k += num-1
    seg[cs][k] = 1
    seg[ls][k] = 0
    while k:
        k = (k-1)//2
        seg[ls][k] = seg[ls][k*2+1] | seg[ls][k*2+2]
        seg[cs][k] = seg[cs][k*2+1] | seg[cs][k*2+2] def update(k, cs):
    ls = s[k]
    if ls == cs:
        return
    k += num-1
    seg[cs][k] = 1
    seg[ls][k] = 0
    while k:
        k = (k-1)//2
        seg[ls][k] = seg[ls][k*2+1] | seg[ls][k*2+2]
        seg[cs][k] = seg[cs][k*2+1] | seg[cs][k*2+2] update def init(init_val):
    for j in range(26):
        #set_val
        for i in range(n):
            if init_val[i] == j:
                seg[j][i+num-1] = 1
        #built
        for i in range(num-2,-1,-1):
            seg[j][i] = seg[j][2*i+1] | seg[j][2*i+2] def init(init_val):
    for j in range(26):
        #set_val
        for i in range(n):
            if init_val[i] == j:
                seg[j][i+num-1] = 1
        #built
        for i in range(num-2,-1,-1):
            seg[j][i] = seg[j][2*i+1] | seg[j][2*i+2] init num = 2**(n-1).bit_length() 2**(n-1).bit_length() num def query(pp, qq): # pからq-1までの最大値
    pp += num-1
    qq += num-2
    total = 0
    for j in range(26):
        p = copy.deepcopy(pp)
        q = copy.deepcopy(qq)
        res = 0
        while q - p > 1:
            if res == 1:
                break
            if p&1 == 0:
                res = res | seg[j][p]
            if q&1 == 1:
                res = res | seg[j][q]
                q -= 1
            p = p//2
            q = (q-1)//2
        if q - p > 1:
            total += res
            continue
        if p == q:
            res = res | seg[j][p]
        else:
            res = res | seg[j][p] | seg[j][q]
        total += res
    return total def query(pp, qq): # pからq-1までの最大値
    pp += num-1
    qq += num-2
    total = 0
    for j in range(26):
        p = copy.deepcopy(pp)
        q = copy.deepcopy(qq)
        res = 0
        while q - p > 1:
            if res == 1:
                break
            if p&1 == 0:
                res = res | seg[j][p]
            if q&1 == 1:
                res = res | seg[j][q]
                q -= 1
            p = p//2
            q = (q-1)//2
        if q - p > 1:
            total += res
            continue
        if p == q:
            res = res | seg[j][p]
        else:
            res = res | seg[j][p] | seg[j][q]
        total += res
    return total query s = list(input()) list(input()) s q = int(input()) int(input()) q p, q = int(cq[1]) - 1, int(cq[2]) int(cq[1]) - 1 p cn, cs = int(cq[1]) - 1, ord(cq[2]) - 97 int(cq[1]) - 1 cn
import copy

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


def update(k, cs):
    ls = s[k]
    if ls == cs:
        return
    k += num-1
    seg[cs][k] = 1
    seg[ls][k] = 0
    while k:
        k = (k-1)//2
        seg[ls][k] = seg[ls][k*2+1] | seg[ls][k*2+2]
        seg[cs][k] = seg[cs][k*2+1] | seg[cs][k*2+2]


def query(pp, qq): # pからq-1までの最大値
    pp += num-1
    qq += num-2
    total = 0
    for j in range(26):
        p = copy.deepcopy(pp)
        q = copy.deepcopy(qq)
        res = 0
        while q - p > 1:
            if res == 1:
                break
            if p&1 == 0:
                res = res | seg[j][p]
            if q&1 == 1:
                res = res | seg[j][q]
                q -= 1
            p = p//2
            q = (q-1)//2
        if q - p > 1:
            total += res
            continue
        if p == q:
            res = res | seg[j][p]
        else:
            res = res | seg[j][p] | seg[j][q]
        total += res
    return total


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

for i in range(n):
    s[i] = ord(s[i]) - 97
#num:n以上の最小の2のべき乗
num = 2**(n-1).bit_length()
seg = [[0]*(2*num) for i in range(26)]
init(s)
for i in range(q):
    cq = list(input().split())
    if cq[0] == '1':
        cn, cs = int(cq[1]) - 1, ord(cq[2]) - 97
        update(cn, cs)
        s[cn] = cs
    if cq[0] == '2':
        p, q = int(cq[1]) - 1, int(cq[2])
        print(query(p, q))
