class segtree:

    def __init__(self, n, identity):
        # 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

    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.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 val_l | val_r

N = int(input())
S = list(input())
Q = int(input())
T = {}
j = 1
for i in range(97, 97+26):
    T[chr(i)] = j
    j *= 2

s_tree = segtree(N+1, 0)

for i in range(N):
    s_tree.update(i+1, T[S[i]])

for i in range(Q):
    A = list(input().split())
    a, b, c = A
    if a == "2":
        K = bin(s_tree.get(int(b), int(c)))[2:]
        d = 0
        for i in K:
            if i == "1":
                d += 1
        print(d)
    else:
        s_tree.update(int(b), T[c]) class segtree:

    def __init__(self, n, identity):
        # 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

    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.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 val_l | val_r segtree def __init__(self, n, identity):
        # 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

     __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 self n n 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.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.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.array[actual_x * 2] | self.array[actual_x * 2 + 1] self.array[actual_x] self.array self array actual_x self.array[actual_x * 2] | self.array[actual_x * 2 + 1] 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 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 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 val_l | val_r val_l | val_r 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 S = list(input()) S list(input()) list input() input Q = int(input()) Q int(input()) int input() input T = {} T {} j = 1 j 1 for i in range(97, 97+26):
    T[chr(i)] = j
    j *= 2 i range(97, 97+26) range 97 97+26 97 26 T[chr(i)] = j T[chr(i)] T chr(i) chr i j j *= 2 j 2 s_tree = segtree(N+1, 0) s_tree segtree(N+1, 0) segtree N+1 N 1 0 for i in range(N):
    s_tree.update(i+1, T[S[i]]) i range(N) range N s_tree.update(i+1, T[S[i]]) s_tree.update s_tree update i+1 i 1 T[S[i]] T S[i] S i for i in range(Q):
    A = list(input().split())
    a, b, c = A
    if a == "2":
        K = bin(s_tree.get(int(b), int(c)))[2:]
        d = 0
        for i in K:
            if i == "1":
                d += 1
        print(d)
    else:
        s_tree.update(int(b), T[c]) i range(Q) range Q A = list(input().split()) A list(input().split()) list input().split() ().split () input split a, b, c = A a A b c if a == "2":
        K = bin(s_tree.get(int(b), int(c)))[2:]
        d = 0
        for i in K:
            if i == "1":
                d += 1
        print(d)
    else:
        s_tree.update(int(b), T[c]) a == "2" a "2" K = bin(s_tree.get(int(b), int(c)))[2:] K bin(s_tree.get(int(b), int(c)))[2:] (s_tree.get(int(b), int(c))) bin s_tree.get(int(b), int(c)) s_tree.get s_tree get int(b) int b int(c) int c 2: 2 d = 0 d 0 for i in K:
            if i == "1":
                d += 1
         i K if i == "1":
                d += 1
         i == "1" i "1" d += 1 d 1 print(d) print d s_tree.update(int(b), T[c]) s_tree.update s_tree update int(b) int b T[c] T c T = {} {} T A = list(input().split()) list(input().split()) A N = int(input()) int(input()) N j = 1 1 j d = 0 0 d d += 1 1 d class segtree:

    def __init__(self, n, identity):
        # 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

    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.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 val_l | val_r class segtree:

    def __init__(self, n, identity):
        # 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

    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.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 val_l | val_r segtree s_tree = segtree(N+1, 0) segtree(N+1, 0) s_tree K = bin(s_tree.get(int(b), int(c)))[2:] bin(s_tree.get(int(b), int(c)))[2:] K Q = int(input()) int(input()) Q j *= 2 2 j a, b, c = A A a b, c = A A b S = list(input()) list(input()) S c = A A c
class segtree:

    def __init__(self, n, identity):
        # 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

    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.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 val_l | val_r

N = int(input())
S = list(input())
Q = int(input())
T = {}
j = 1
for i in range(97, 97+26):
    T[chr(i)] = j
    j *= 2

s_tree = segtree(N+1, 0)

for i in range(N):
    s_tree.update(i+1, T[S[i]])

for i in range(Q):
    A = list(input().split())
    a, b, c = A
    if a == "2":
        K = bin(s_tree.get(int(b), int(c)))[2:]
        d = 0
        for i in K:
            if i == "1":
                d += 1
        print(d)
    else:
        s_tree.update(int(b), T[c])