import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
import bisect

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_end_leaves = 2**(len(nb)-1)
        else:
            self.num_end_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_end_leaves * 2)]
        self.identity = identity
        self.operator =operator

    def update(self,x,val):
        actual_x = x+self.num_end_leaves
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_end_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r)

n = int(input())
s = [ c for c in input()]
q = int(input())
qqq = list(map(lambda s: s.strip().split(), sys.stdin.readlines()))

seg = segtree(n+1, lambda a,b:a|b, 0)

for i,c in enumerate(s):
    o = ord(c) - ord("a")
    seg.update(i, 2**o)
# log(chars)

for que in qqq:
    if que[0] == "1":
        target = int(que[1])-1
        o = ord(que[2]) - ord("a")
        seg.update(target, 2**o)

    else:
        left = int(que[1])-1
        right = int(que[2])-1

        x = seg.get(left, right)
        log("x", x)
        count = 0
        while x > 0:
            if x % 2 == 1:
                count += 1
            x = x//2
        print(count) import math math from functools import reduce from collections import deque import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 import bisect bisect def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。 get_nums_l int(s) for s in input().split(" ") for s in input().split(" ") s input().split(" ") ().split () input split " " for s in input().split(" ") int(s) int s return [ int(s) for s in input().split(" ")] [ int(s) for s in input().split(" ")] def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。 get_nums_n int(input()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(input()) int input() input return [ int(input()) for _ in range(n)] [ int(input()) for _ in range(n)] n n def get_all_int():
    return map(int, open(0).read().split()) get_all_int return map(int, open(0).read().split()) map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split def log(*args):
    print("DEBUG:", *args, file=sys.stderr) log print("DEBUG:", *args, file=sys.stderr) print "DEBUG:" *args args file=sys.stderr file sys.stderr sys stderr *args class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_end_leaves = 2**(len(nb)-1)
        else:
            self.num_end_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_end_leaves * 2)]
        self.identity = identity
        self.operator =operator

    def update(self,x,val):
        actual_x = x+self.num_end_leaves
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_end_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r) segtree def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_end_leaves = 2**(len(nb)-1)
        else:
            self.num_end_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_end_leaves * 2)]
        self.identity = identity
        self.operator =operator

     __init__ nb = bin(n)[2:] nb bin(n)[2:] (n) bin n 2: 2 int(digit) for digit in nb for digit in nb digit nb for digit in nb int(digit) int digit bc = sum([int(digit) for digit in nb]) bc sum([int(digit) for digit in nb]) sum [int(digit) for digit in nb] if bc == 1:
            self.num_end_leaves = 2**(len(nb)-1)
        else:
            self.num_end_leaves = 2**(len(nb))

         bc == 1 bc 1 self.num_end_leaves = 2**(len(nb)-1) self.num_end_leaves self num_end_leaves 2**(len(nb)-1) 2 len(nb)-1 len(nb) len nb 1 self.num_end_leaves = 2**(len(nb)) self.num_end_leaves self num_end_leaves 2**(len(nb)) 2 len(nb) len nb identity for i in range(self.num_end_leaves * 2) for i in range(self.num_end_leaves * 2) i range(self.num_end_leaves * 2) range self.num_end_leaves * 2 self.num_end_leaves self num_end_leaves 2 for i in range(self.num_end_leaves * 2) identity self.array = [identity for i in range(self.num_end_leaves * 2)] self.array self array [identity for i in range(self.num_end_leaves * 2)] self.identity = identity self.identity self identity identity self.operator =operator self.operator self operator operator self self n n operator operator identity identity def update(self,x,val):
        actual_x = x+self.num_end_leaves
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

     update actual_x = x+self.num_end_leaves actual_x x+self.num_end_leaves x self.num_end_leaves self num_end_leaves self.array[actual_x] = val self.array[actual_x] self.array self array actual_x val while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

     actual_x > 0 actual_x 0 actual_x = actual_x//2 actual_x actual_x//2 actual_x 2 self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1]) self.array[actual_x] self.array self array actual_x self.operator(self.array[actual_x*2],self.array[actual_x*2+1]) self.operator self operator self.array[actual_x*2] self.array self array actual_x*2 actual_x 2 self.array[actual_x*2+1] self.array self array actual_x*2+1 actual_x*2 actual_x 2 1 self self x x val val def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_end_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r) get width_of_floor = self.num_end_leaves//(2**depth) width_of_floor self.num_end_leaves//(2**depth) self.num_end_leaves self num_end_leaves 2**depth 2 depth leaf_right = leaf_left+width_of_floor-1 leaf_right leaf_left+width_of_floor-1 leaf_left+width_of_floor leaf_left width_of_floor 1 if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r) leaf_left > q_right or leaf_right < q_left leaf_left > q_right leaf_left q_right leaf_right < q_left leaf_right q_left return  self.identity self.identity self identity elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

         leaf_left >= q_left and leaf_right <= q_right leaf_left >= q_left leaf_left q_left leaf_right <= q_right leaf_right q_right return self.array[arr_ind] self.array[arr_ind] self.array self array arr_ind val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1) val_l self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1) self.get self get q_left q_right 2*arr_ind 2 arr_ind leaf_left depth+1 depth 1 val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1) val_r self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1) self.get self get q_left q_right 2*arr_ind+1 2*arr_ind 2 arr_ind 1 leaf_left+width_of_floor//2 leaf_left width_of_floor//2 width_of_floor 2 depth+1 depth 1 return self.operator(val_l,val_r) self.operator(val_l,val_r) self.operator self operator val_l val_r self self q_left q_left q_right q_right arr_ind=1 arr_ind 1 leaf_left=0 leaf_left 0 depth=0 depth 0 n = int(input()) n int(input()) int input() input c for c in input() for c in input() c input() input for c in input() c s = [ c for c in input()] s [ c for c in input()] q = int(input()) q int(input()) int input() input qqq = list(map(lambda s: s.strip().split(), sys.stdin.readlines())) qqq list(map(lambda s: s.strip().split(), sys.stdin.readlines())) list map(lambda s: s.strip().split(), sys.stdin.readlines()) map lambda s: s.strip().split() s.strip().split() s.strip().split s.strip() s.strip s strip split s sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines seg = segtree(n+1, lambda a,b:a|b, 0) seg segtree(n+1, lambda a,b:a|b, 0) segtree n+1 n 1 lambda a,b:a|b a|b a b a b 0 for i,c in enumerate(s):
    o = ord(c) - ord("a")
    seg.update(i, 2**o)
# log(chars) i c enumerate(s) enumerate s o = ord(c) - ord("a") o ord(c) - ord("a") ord(c) ord c ord("a") ord "a" seg.update(i, 2**o) seg.update seg update i 2**o 2 o for que in qqq:
    if que[0] == "1":
        target = int(que[1])-1
        o = ord(que[2]) - ord("a")
        seg.update(target, 2**o)

    else:
        left = int(que[1])-1
        right = int(que[2])-1

        x = seg.get(left, right)
        log("x", x)
        count = 0
        while x > 0:
            if x % 2 == 1:
                count += 1
            x = x//2
        print(count) que qqq if que[0] == "1":
        target = int(que[1])-1
        o = ord(que[2]) - ord("a")
        seg.update(target, 2**o)

    else:
        left = int(que[1])-1
        right = int(que[2])-1

        x = seg.get(left, right)
        log("x", x)
        count = 0
        while x > 0:
            if x % 2 == 1:
                count += 1
            x = x//2
        print(count) que[0] == "1" que[0] que 0 "1" target = int(que[1])-1 target int(que[1])-1 int(que[1]) int que[1] que 1 1 o = ord(que[2]) - ord("a") o ord(que[2]) - ord("a") ord(que[2]) ord que[2] que 2 ord("a") ord "a" seg.update(target, 2**o) seg.update seg update target 2**o 2 o left = int(que[1])-1 left int(que[1])-1 int(que[1]) int que[1] que 1 1 right = int(que[2])-1 right int(que[2])-1 int(que[2]) int que[2] que 2 1 x = seg.get(left, right) x seg.get(left, right) seg.get seg get left right log("x", x) log "x" x count = 0 count 0 while x > 0:
            if x % 2 == 1:
                count += 1
            x = x//2
         x > 0 x 0 if x % 2 == 1:
                count += 1
             x % 2 == 1 x % 2 x 2 1 count += 1 count 1 x = x//2 x x//2 x 2 print(count) print count seg = segtree(n+1, lambda a,b:a|b, 0) segtree(n+1, lambda a,b:a|b, 0) seg s = [ c for c in input()] [ c for c in input()] s count = 0 0 count qqq = list(map(lambda s: s.strip().split(), sys.stdin.readlines())) list(map(lambda s: s.strip().split(), sys.stdin.readlines())) qqq class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_end_leaves = 2**(len(nb)-1)
        else:
            self.num_end_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_end_leaves * 2)]
        self.identity = identity
        self.operator =operator

    def update(self,x,val):
        actual_x = x+self.num_end_leaves
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_end_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r) class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_end_leaves = 2**(len(nb)-1)
        else:
            self.num_end_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_end_leaves * 2)]
        self.identity = identity
        self.operator =operator

    def update(self,x,val):
        actual_x = x+self.num_end_leaves
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_end_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r) segtree o = ord(c) - ord("a") ord(c) - ord("a") o x = seg.get(left, right) seg.get(left, right) x def get_all_int():
    return map(int, open(0).read().split()) def get_all_int():
    return map(int, open(0).read().split()) get_all_int o = ord(que[2]) - ord("a") ord(que[2]) - ord("a") o left = int(que[1])-1 int(que[1])-1 left count += 1 1 count def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。 def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。 get_nums_n n = int(input()) int(input()) n right = int(que[2])-1 int(que[2])-1 right x = x//2 x//2 x q = int(input()) int(input()) q def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。 def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。 get_nums_l target = int(que[1])-1 int(que[1])-1 target def log(*args):
    print("DEBUG:", *args, file=sys.stderr) def log(*args):
    print("DEBUG:", *args, file=sys.stderr) log
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
import bisect

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_end_leaves = 2**(len(nb)-1)
        else:
            self.num_end_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_end_leaves * 2)]
        self.identity = identity
        self.operator =operator

    def update(self,x,val):
        actual_x = x+self.num_end_leaves
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_end_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r)

n = int(input())
s = [ c for c in input()]
q = int(input())
qqq = list(map(lambda s: s.strip().split(), sys.stdin.readlines()))

seg = segtree(n+1, lambda a,b:a|b, 0)

for i,c in enumerate(s):
    o = ord(c) - ord("a")
    seg.update(i, 2**o)
# log(chars)

for que in qqq:
    if que[0] == "1":
        target = int(que[1])-1
        o = ord(que[2]) - ord("a")
        seg.update(target, 2**o)

    else:
        left = int(que[1])-1
        right = int(que[2])-1

        x = seg.get(left, right)
        log("x", x)
        count = 0
        while x > 0:
            if x % 2 == 1:
                count += 1
            x = x//2
        print(count)
