import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



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

### BIT 
def init(bit, values):
    for i,v in enumerate(values):
        update(bit,i,v)
#a1 ~ aiまでの和 O(logn)
def query(bit,i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i&(-i)
    return res

#ai += x(logN)
def update(bit,i,x):
    while i <= len(bit)-1:
        bit[i] += x
        i += i&(-i)
    return

l = [chr(v) for v in range(ord("a"), ord("z")+1)]
d = {c: [0] * (n+1) for c in l}
for i,c in enumerate(s):
    update(d[c], i+1, 1)
s = list(s)
ans = []
for i in range(q):
    v,i,c = input().split()
    if v=="1":
        i = int(i)-1
        if d[s[i]][i+1]>=1:
            update(d[s[i]], i+1, -1)
        update(d[c], i+1, 1)
        s[i] = c
    else:
        ll,rr = int(i),int(c)
        val = sum(query(d[c], rr) - query(d[c], ll-1) >= 1 for c in l)
        ans.append(val)
write("\n".join(map(str, ans))) import sys sys input = lambda : sys.stdin.readline().rstrip() input lambda : sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip sys.setrecursionlimit(max(1000, 10**9)) sys.setrecursionlimit sys setrecursionlimit max(1000, 10**9) max 1000 10**9 10 9 write = lambda x: sys.stdout.write(x+"\n") write lambda x: sys.stdout.write(x+"\n") sys.stdout.write(x+"\n") sys.stdout.write sys.stdout sys stdout write x+"\n" x "\n" x n = int(input()) n int(input()) int input() input s = input() s input() input q = int(input()) q int(input()) int input() input def init(bit, values):
    for i,v in enumerate(values):
        update(bit,i,v)
#a1 ~ aiまでの和 O(logn) init for i,v in enumerate(values):
        update(bit,i,v)
#a1 ~ aiまでの和 O(logn) i v enumerate(values) enumerate values update(bit,i,v) update bit i v bit bit values values def query(bit,i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i&(-i)
    return res

#ai += x(logN) query res = 0 res 0 while i > 0:
        res += bit[i]
        i -= i&(-i)
     i > 0 i 0 res += bit[i] res bit[i] bit i i -= i&(-i) i i&(-i) i -i i return res res bit bit i i def update(bit,i,x):
    while i <= len(bit)-1:
        bit[i] += x
        i += i&(-i)
    return update while i <= len(bit)-1:
        bit[i] += x
        i += i&(-i)
     i <= len(bit)-1 i len(bit)-1 len(bit) len bit 1 bit[i] += x bit[i] bit i x i += i&(-i) i i&(-i) i -i i return bit bit i i x x chr(v) for v in range(ord("a"), ord("z")+1) for v in range(ord("a"), ord("z")+1) v range(ord("a"), ord("z")+1) range ord("a") ord "a" ord("z")+1 ord("z") ord "z" 1 for v in range(ord("a"), ord("z")+1) chr(v) chr v l = [chr(v) for v in range(ord("a"), ord("z")+1)] l [chr(v) for v in range(ord("a"), ord("z")+1)] c: [0] * (n+1) for c in l for c in l c l for c in l c [0] * (n+1) [0] 0 n+1 n 1 d = {c: [0] * (n+1) for c in l} d {c: [0] * (n+1) for c in l} for i,c in enumerate(s):
    update(d[c], i+1, 1) i c enumerate(s) enumerate s update(d[c], i+1, 1) update d[c] d c i+1 i 1 1 s = list(s) s list(s) list s ans = [] ans [] for i in range(q):
    v,i,c = input().split()
    if v=="1":
        i = int(i)-1
        if d[s[i]][i+1]>=1:
            update(d[s[i]], i+1, -1)
        update(d[c], i+1, 1)
        s[i] = c
    else:
        ll,rr = int(i),int(c)
        val = sum(query(d[c], rr) - query(d[c], ll-1) >= 1 for c in l)
        ans.append(val) i range(q) range q v,i,c = input().split() v input().split() ().split () input split i c if v=="1":
        i = int(i)-1
        if d[s[i]][i+1]>=1:
            update(d[s[i]], i+1, -1)
        update(d[c], i+1, 1)
        s[i] = c
    else:
        ll,rr = int(i),int(c)
        val = sum(query(d[c], rr) - query(d[c], ll-1) >= 1 for c in l)
        ans.append(val) v=="1" v "1" i = int(i)-1 i int(i)-1 int(i) int i 1 if d[s[i]][i+1]>=1:
            update(d[s[i]], i+1, -1)
         d[s[i]][i+1]>=1 d[s[i]][i+1] [s[i]] d s[i] s i i+1 i 1 1 update(d[s[i]], i+1, -1) update d[s[i]] d s[i] s i i+1 i 1 -1 update(d[c], i+1, 1) update d[c] d c i+1 i 1 1 s[i] = c s[i] s i c ll,rr = int(i),int(c) ll int(i) int i rr int(c) int c val = sum(query(d[c], rr) - query(d[c], ll-1) >= 1 for c in l) val sum(query(d[c], rr) - query(d[c], ll-1) >= 1 for c in l) sum query(d[c], rr) - query(d[c], ll-1) >= 1 query(d[c], rr) - query(d[c], ll-1) query(d[c], rr) query d[c] d c rr query(d[c], ll-1) query d[c] d c ll-1 ll 1 1 ans.append(val) ans.append ans append val write("\n".join(map(str, ans))) write "\n".join(map(str, ans)) "\n".join "\n" join map(str, ans) map str ans d = {c: [0] * (n+1) for c in l} {c: [0] * (n+1) for c in l} d v,i,c = input().split() input().split() v def init(bit, values):
    for i,v in enumerate(values):
        update(bit,i,v)
#a1 ~ aiまでの和 O(logn) def init(bit, values):
    for i,v in enumerate(values):
        update(bit,i,v)
#a1 ~ aiまでの和 O(logn) init q = int(input()) int(input()) q val = sum(query(d[c], rr) - query(d[c], ll-1) >= 1 for c in l) sum(query(d[c], rr) - query(d[c], ll-1) >= 1 for c in l) val s = input() input() s rr = int(i),int(c) int(c) rr input = lambda : sys.stdin.readline().rstrip() lambda : sys.stdin.readline().rstrip() input write = lambda x: sys.stdout.write(x+"\n") lambda x: sys.stdout.write(x+"\n") write n = int(input()) int(input()) n def update(bit,i,x):
    while i <= len(bit)-1:
        bit[i] += x
        i += i&(-i)
    return def update(bit,i,x):
    while i <= len(bit)-1:
        bit[i] += x
        i += i&(-i)
    return update ll,rr = int(i),int(c) int(i) ll def query(bit,i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i&(-i)
    return res

#ai += x(logN) def query(bit,i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i&(-i)
    return res

#ai += x(logN) query s = list(s) list(s) s ans = [] [] ans c = input().split() input().split() c i = int(i)-1 int(i)-1 i i,c = input().split() input().split() i l = [chr(v) for v in range(ord("a"), ord("z")+1)] [chr(v) for v in range(ord("a"), ord("z")+1)] l
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



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

### BIT 
def init(bit, values):
    for i,v in enumerate(values):
        update(bit,i,v)
#a1 ~ aiまでの和 O(logn)
def query(bit,i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i&(-i)
    return res

#ai += x(logN)
def update(bit,i,x):
    while i <= len(bit)-1:
        bit[i] += x
        i += i&(-i)
    return

l = [chr(v) for v in range(ord("a"), ord("z")+1)]
d = {c: [0] * (n+1) for c in l}
for i,c in enumerate(s):
    update(d[c], i+1, 1)
s = list(s)
ans = []
for i in range(q):
    v,i,c = input().split()
    if v=="1":
        i = int(i)-1
        if d[s[i]][i+1]>=1:
            update(d[s[i]], i+1, -1)
        update(d[c], i+1, 1)
        s[i] = c
    else:
        ll,rr = int(i),int(c)
        val = sum(query(d[c], rr) - query(d[c], ll-1) >= 1 for c in l)
        ans.append(val)
write("\n".join(map(str, ans)))