def ctoi(x):
    return ord(x)-ord("a")
n = int(input())
s = list(input())
q = int(input())
bit = [[0]*(n+1) for _ in range(26)]

def update(pos,a,x):
    while pos<=n:
        bit[a][pos] += x
        pos += pos&(-pos)

def query(pos):
    ret=[0]*26
    for i in range(26):
        tmp=0
        p=pos
        while p>0:
            tmp+=bit[i][p]
            p-=p&(-p)
        ret[i]=tmp
    return ret

for i in range(n):
    update(i+1,ctoi(s[i]),1)

for _ in range(q):
    flag,a,b = input().split()
    flag=int(flag)
    a=int(a)
    if flag==1:
        if s[a-1]==b:
            continue
        else:
            update(a,ctoi(s[a-1]),-1)
            update(a,ctoi(b),1)
            s[a-1]=b
    else:
        b=int(b)
        c1 = query(b)
        c2 = query(a-1)
        ans = 0
        for i in range(26):
            if c1[i]-c2[i]>0:
                ans += 1
        print(ans) def ctoi(x):
    return ord(x)-ord("a") ctoi return ord(x)-ord("a") ord(x)-ord("a") ord(x) ord x ord("a") ord "a" x x 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 [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 update(pos,a,x):
    while pos<=n:
        bit[a][pos] += x
        pos += pos&(-pos) update while pos<=n:
        bit[a][pos] += x
        pos += pos&(-pos) pos<=n pos n bit[a][pos] += x bit[a][pos] [a] bit a pos x pos += pos&(-pos) pos pos&(-pos) pos -pos pos pos pos a a x x def query(pos):
    ret=[0]*26
    for i in range(26):
        tmp=0
        p=pos
        while p>0:
            tmp+=bit[i][p]
            p-=p&(-p)
        ret[i]=tmp
    return ret query ret=[0]*26 ret [0]*26 [0] 0 26 for i in range(26):
        tmp=0
        p=pos
        while p>0:
            tmp+=bit[i][p]
            p-=p&(-p)
        ret[i]=tmp
     i range(26) range 26 tmp=0 tmp 0 p=pos p pos while p>0:
            tmp+=bit[i][p]
            p-=p&(-p)
         p>0 p 0 tmp+=bit[i][p] tmp bit[i][p] [i] bit i p p-=p&(-p) p p&(-p) p -p p ret[i]=tmp ret[i] ret i tmp return ret ret pos pos for i in range(n):
    update(i+1,ctoi(s[i]),1) i range(n) range n update(i+1,ctoi(s[i]),1) update i+1 i 1 ctoi(s[i]) ctoi s[i] s i 1 for _ in range(q):
    flag,a,b = input().split()
    flag=int(flag)
    a=int(a)
    if flag==1:
        if s[a-1]==b:
            continue
        else:
            update(a,ctoi(s[a-1]),-1)
            update(a,ctoi(b),1)
            s[a-1]=b
    else:
        b=int(b)
        c1 = query(b)
        c2 = query(a-1)
        ans = 0
        for i in range(26):
            if c1[i]-c2[i]>0:
                ans += 1
        print(ans) _ range(q) range q flag,a,b = input().split() flag input().split() ().split () input split a b flag=int(flag) flag int(flag) int flag a=int(a) a int(a) int a if flag==1:
        if s[a-1]==b:
            continue
        else:
            update(a,ctoi(s[a-1]),-1)
            update(a,ctoi(b),1)
            s[a-1]=b
    else:
        b=int(b)
        c1 = query(b)
        c2 = query(a-1)
        ans = 0
        for i in range(26):
            if c1[i]-c2[i]>0:
                ans += 1
        print(ans) flag==1 flag 1 if s[a-1]==b:
            continue
        else:
            update(a,ctoi(s[a-1]),-1)
            update(a,ctoi(b),1)
            s[a-1]=b
     s[a-1]==b s[a-1] s a-1 a 1 b continue update(a,ctoi(s[a-1]),-1) update a ctoi(s[a-1]) ctoi s[a-1] s a-1 a 1 -1 update(a,ctoi(b),1) update a ctoi(b) ctoi b 1 s[a-1]=b s[a-1] s a-1 a 1 b b=int(b) b int(b) int b c1 = query(b) c1 query(b) query b c2 = query(a-1) c2 query(a-1) query a-1 a 1 ans = 0 ans 0 for i in range(26):
            if c1[i]-c2[i]>0:
                ans += 1
         i range(26) range 26 if c1[i]-c2[i]>0:
                ans += 1
         c1[i]-c2[i]>0 c1[i]-c2[i] c1[i] c1 i c2[i] c2 i 0 ans += 1 ans 1 print(ans) print ans flag=int(flag) int(flag) flag c1 = query(b) query(b) c1 flag,a,b = input().split() input().split() flag n = int(input()) int(input()) n q = int(input()) int(input()) q def update(pos,a,x):
    while pos<=n:
        bit[a][pos] += x
        pos += pos&(-pos) def update(pos,a,x):
    while pos<=n:
        bit[a][pos] += x
        pos += pos&(-pos) update a,b = input().split() input().split() a b=int(b) int(b) b b = input().split() input().split() b c2 = query(a-1) query(a-1) c2 def ctoi(x):
    return ord(x)-ord("a") def ctoi(x):
    return ord(x)-ord("a") ctoi ans += 1 1 ans ans = 0 0 ans bit = [[0]*(n+1) for _ in range(26)] [[0]*(n+1) for _ in range(26)] bit s = list(input()) list(input()) s a=int(a) int(a) a def query(pos):
    ret=[0]*26
    for i in range(26):
        tmp=0
        p=pos
        while p>0:
            tmp+=bit[i][p]
            p-=p&(-p)
        ret[i]=tmp
    return ret def query(pos):
    ret=[0]*26
    for i in range(26):
        tmp=0
        p=pos
        while p>0:
            tmp+=bit[i][p]
            p-=p&(-p)
        ret[i]=tmp
    return ret query
def ctoi(x):
    return ord(x)-ord("a")
n = int(input())
s = list(input())
q = int(input())
bit = [[0]*(n+1) for _ in range(26)]

def update(pos,a,x):
    while pos<=n:
        bit[a][pos] += x
        pos += pos&(-pos)

def query(pos):
    ret=[0]*26
    for i in range(26):
        tmp=0
        p=pos
        while p>0:
            tmp+=bit[i][p]
            p-=p&(-p)
        ret[i]=tmp
    return ret

for i in range(n):
    update(i+1,ctoi(s[i]),1)

for _ in range(q):
    flag,a,b = input().split()
    flag=int(flag)
    a=int(a)
    if flag==1:
        if s[a-1]==b:
            continue
        else:
            update(a,ctoi(s[a-1]),-1)
            update(a,ctoi(b),1)
            s[a-1]=b
    else:
        b=int(b)
        c1 = query(b)
        c2 = query(a-1)
        ans = 0
        for i in range(26):
            if c1[i]-c2[i]>0:
                ans += 1
        print(ans)