import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def _get(T, a, b, k, l, r):
    if r <= a or b <= l:
        return set()

    if a <= l and r <= b:
        return T[k]
    else:
        s1 = _get(T, a, b, 2 * k + 1, l, (l + r) // 2)
        s2 = _get(T, a, b, 2 * k + 2, (l + r) // 2, r)
        return s1.union(s2)


def get(T, d, a, b):
    return _get(T, a, b, 0, 0, 2 ** d)


def main():
    N = int(input())
    S = input().strip()
    Q = [input().strip().split() for _ in range(int(input()))]
    d = N.bit_length()
    T = [set() for _ in range(2 ** (d + 1) - 1)]
    for i, s in enumerate(S):
        T[i + 2 ** d - 1].add(s)
    for i in range(2 ** d - 2, -1, -1):
        T[i] =T[2 * i + 1] .union(T[2 * i + 2])

    for s, a, b in Q:
        if s == "1":
            a = int(a) - 1
            i = a + 2 ** d - 1
            if b in T[i]:
                continue
            T[i] = {b}
            while i > 0:
                i = (i - 1) // 2
                T[i] = T[2 * i + 1] .union(T[2 * i + 2])
        elif s == "2":
            a = int(a) - 1
            b = int(b) - 1
            S = get(T, d, a, b + 1)
            print(len(S))


if __name__ == "__main__":
    main() import sys sys from collections import deque import bisect bisect import copy copy import heapq heapq import itertools itertools import math math input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 def read_values(): return map(int, input().split()) read_values def read_index(): return map(lambda x: int(x) - 1, input().split()) read_index def read_list(): return list(read_values()) read_list read_list() for n in range(N) for n in range(N) n range(N) range N for n in range(N) read_list() read_list def read_lists(N): return [read_list() for n in range(N)] read_lists N N def _get(T, a, b, k, l, r):
    if r <= a or b <= l:
        return set()

    if a <= l and r <= b:
        return T[k]
    else:
        s1 = _get(T, a, b, 2 * k + 1, l, (l + r) // 2)
        s2 = _get(T, a, b, 2 * k + 2, (l + r) // 2, r)
        return s1.union(s2) _get if r <= a or b <= l:
        return set()

     r <= a or b <= l r <= a r a b <= l b l return set() set() set if a <= l and r <= b:
        return T[k]
    else:
        s1 = _get(T, a, b, 2 * k + 1, l, (l + r) // 2)
        s2 = _get(T, a, b, 2 * k + 2, (l + r) // 2, r)
        return s1.union(s2) a <= l and r <= b a <= l a l r <= b r b return T[k] T[k] T k s1 = _get(T, a, b, 2 * k + 1, l, (l + r) // 2) s1 _get(T, a, b, 2 * k + 1, l, (l + r) // 2) _get T a b 2 * k + 1 2 * k 2 k 1 l (l + r) // 2 l + r l r 2 s2 = _get(T, a, b, 2 * k + 2, (l + r) // 2, r) s2 _get(T, a, b, 2 * k + 2, (l + r) // 2, r) _get T a b 2 * k + 2 2 * k 2 k 2 (l + r) // 2 l + r l r 2 r return s1.union(s2) s1.union(s2) s1.union s1 union s2 T T a a b b k k l l r r def get(T, d, a, b):
    return _get(T, a, b, 0, 0, 2 ** d) get return _get(T, a, b, 0, 0, 2 ** d) _get(T, a, b, 0, 0, 2 ** d) _get T a b 0 0 2 ** d 2 d T T d d a a b b def main():
    N = int(input())
    S = input().strip()
    Q = [input().strip().split() for _ in range(int(input()))]
    d = N.bit_length()
    T = [set() for _ in range(2 ** (d + 1) - 1)]
    for i, s in enumerate(S):
        T[i + 2 ** d - 1].add(s)
    for i in range(2 ** d - 2, -1, -1):
        T[i] =T[2 * i + 1] .union(T[2 * i + 2])

    for s, a, b in Q:
        if s == "1":
            a = int(a) - 1
            i = a + 2 ** d - 1
            if b in T[i]:
                continue
            T[i] = {b}
            while i > 0:
                i = (i - 1) // 2
                T[i] = T[2 * i + 1] .union(T[2 * i + 2])
        elif s == "2":
            a = int(a) - 1
            b = int(b) - 1
            S = get(T, d, a, b + 1)
            print(len(S)) main N = int(input()) N int(input()) int input() input S = input().strip() S input().strip() ().strip () input strip input().strip().split() for _ in range(int(input())) for _ in range(int(input())) _ range(int(input())) range int(input()) int input() input for _ in range(int(input())) input().strip().split() ().strip().split ().strip() ().strip () input strip split Q = [input().strip().split() for _ in range(int(input()))] Q [input().strip().split() for _ in range(int(input()))] d = N.bit_length() d N.bit_length() N.bit_length N bit_length set() for _ in range(2 ** (d + 1) - 1) for _ in range(2 ** (d + 1) - 1) _ range(2 ** (d + 1) - 1) range 2 ** (d + 1) - 1 2 ** (d + 1) 2 d + 1 d 1 1 for _ in range(2 ** (d + 1) - 1) set() set T = [set() for _ in range(2 ** (d + 1) - 1)] T [set() for _ in range(2 ** (d + 1) - 1)] for i, s in enumerate(S):
        T[i + 2 ** d - 1].add(s)
     i s enumerate(S) enumerate S T[i + 2 ** d - 1].add(s) [i + 2 ** d - 1].add [i + 2 ** d - 1] T i + 2 ** d - 1 i + 2 ** d i 2 ** d 2 d 1 add s for i in range(2 ** d - 2, -1, -1):
        T[i] =T[2 * i + 1] .union(T[2 * i + 2])

     i range(2 ** d - 2, -1, -1) range 2 ** d - 2 2 ** d 2 d 2 -1 -1 T[i] =T[2 * i + 1] .union(T[2 * i + 2]) T[i] T i T[2 * i + 1] .union(T[2 * i + 2]) [2 * i + 1] .union [2 * i + 1] T 2 * i + 1 2 * i 2 i 1 union T[2 * i + 2] T 2 * i + 2 2 * i 2 i 2 for s, a, b in Q:
        if s == "1":
            a = int(a) - 1
            i = a + 2 ** d - 1
            if b in T[i]:
                continue
            T[i] = {b}
            while i > 0:
                i = (i - 1) // 2
                T[i] = T[2 * i + 1] .union(T[2 * i + 2])
        elif s == "2":
            a = int(a) - 1
            b = int(b) - 1
            S = get(T, d, a, b + 1)
            print(len(S)) s a b Q if s == "1":
            a = int(a) - 1
            i = a + 2 ** d - 1
            if b in T[i]:
                continue
            T[i] = {b}
            while i > 0:
                i = (i - 1) // 2
                T[i] = T[2 * i + 1] .union(T[2 * i + 2])
        elif s == "2":
            a = int(a) - 1
            b = int(b) - 1
            S = get(T, d, a, b + 1)
            print(len(S)) s == "1" s "1" a = int(a) - 1 a int(a) - 1 int(a) int a 1 i = a + 2 ** d - 1 i a + 2 ** d - 1 a + 2 ** d a 2 ** d 2 d 1 if b in T[i]:
                continue
             b in T[i] b T[i] T i continue T[i] = {b} T[i] T i {b} while i > 0:
                i = (i - 1) // 2
                T[i] = T[2 * i + 1] .union(T[2 * i + 2])
         i > 0 i 0 i = (i - 1) // 2 i (i - 1) // 2 i - 1 i 1 2 T[i] = T[2 * i + 1] .union(T[2 * i + 2]) T[i] T i T[2 * i + 1] .union(T[2 * i + 2]) [2 * i + 1] .union [2 * i + 1] T 2 * i + 1 2 * i 2 i 1 union T[2 * i + 2] T 2 * i + 2 2 * i 2 i 2 elif s == "2":
            a = int(a) - 1
            b = int(b) - 1
            S = get(T, d, a, b + 1)
            print(len(S)) s == "2" s "2" a = int(a) - 1 a int(a) - 1 int(a) int a 1 b = int(b) - 1 b int(b) - 1 int(b) int b 1 S = get(T, d, a, b + 1) S get(T, d, a, b + 1) get T d a b + 1 b 1 print(len(S)) print len(S) len S if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def read_index(): return map(lambda x: int(x) - 1, input().split()) def read_index(): return map(lambda x: int(x) - 1, input().split()) read_index def read_list(): return list(read_values()) def read_list(): return list(read_values()) read_list def _get(T, a, b, k, l, r):
    if r <= a or b <= l:
        return set()

    if a <= l and r <= b:
        return T[k]
    else:
        s1 = _get(T, a, b, 2 * k + 1, l, (l + r) // 2)
        s2 = _get(T, a, b, 2 * k + 2, (l + r) // 2, r)
        return s1.union(s2) def _get(T, a, b, k, l, r):
    if r <= a or b <= l:
        return set()

    if a <= l and r <= b:
        return T[k]
    else:
        s1 = _get(T, a, b, 2 * k + 1, l, (l + r) // 2)
        s2 = _get(T, a, b, 2 * k + 2, (l + r) // 2, r)
        return s1.union(s2) _get input = sys.stdin.readline sys.stdin.readline input def read_lists(N): return [read_list() for n in range(N)] def read_lists(N): return [read_list() for n in range(N)] read_lists def get(T, d, a, b):
    return _get(T, a, b, 0, 0, 2 ** d) def get(T, d, a, b):
    return _get(T, a, b, 0, 0, 2 ** d) get def main():
    N = int(input())
    S = input().strip()
    Q = [input().strip().split() for _ in range(int(input()))]
    d = N.bit_length()
    T = [set() for _ in range(2 ** (d + 1) - 1)]
    for i, s in enumerate(S):
        T[i + 2 ** d - 1].add(s)
    for i in range(2 ** d - 2, -1, -1):
        T[i] =T[2 * i + 1] .union(T[2 * i + 2])

    for s, a, b in Q:
        if s == "1":
            a = int(a) - 1
            i = a + 2 ** d - 1
            if b in T[i]:
                continue
            T[i] = {b}
            while i > 0:
                i = (i - 1) // 2
                T[i] = T[2 * i + 1] .union(T[2 * i + 2])
        elif s == "2":
            a = int(a) - 1
            b = int(b) - 1
            S = get(T, d, a, b + 1)
            print(len(S)) def main():
    N = int(input())
    S = input().strip()
    Q = [input().strip().split() for _ in range(int(input()))]
    d = N.bit_length()
    T = [set() for _ in range(2 ** (d + 1) - 1)]
    for i, s in enumerate(S):
        T[i + 2 ** d - 1].add(s)
    for i in range(2 ** d - 2, -1, -1):
        T[i] =T[2 * i + 1] .union(T[2 * i + 2])

    for s, a, b in Q:
        if s == "1":
            a = int(a) - 1
            i = a + 2 ** d - 1
            if b in T[i]:
                continue
            T[i] = {b}
            while i > 0:
                i = (i - 1) // 2
                T[i] = T[2 * i + 1] .union(T[2 * i + 2])
        elif s == "2":
            a = int(a) - 1
            b = int(b) - 1
            S = get(T, d, a, b + 1)
            print(len(S)) main def read_values(): return map(int, input().split()) def read_values(): return map(int, input().split()) read_values mod = 10 ** 9 + 7 10 ** 9 + 7 mod
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def _get(T, a, b, k, l, r):
    if r <= a or b <= l:
        return set()

    if a <= l and r <= b:
        return T[k]
    else:
        s1 = _get(T, a, b, 2 * k + 1, l, (l + r) // 2)
        s2 = _get(T, a, b, 2 * k + 2, (l + r) // 2, r)
        return s1.union(s2)


def get(T, d, a, b):
    return _get(T, a, b, 0, 0, 2 ** d)


def main():
    N = int(input())
    S = input().strip()
    Q = [input().strip().split() for _ in range(int(input()))]
    d = N.bit_length()
    T = [set() for _ in range(2 ** (d + 1) - 1)]
    for i, s in enumerate(S):
        T[i + 2 ** d - 1].add(s)
    for i in range(2 ** d - 2, -1, -1):
        T[i] =T[2 * i + 1] .union(T[2 * i + 2])

    for s, a, b in Q:
        if s == "1":
            a = int(a) - 1
            i = a + 2 ** d - 1
            if b in T[i]:
                continue
            T[i] = {b}
            while i > 0:
                i = (i - 1) // 2
                T[i] = T[2 * i + 1] .union(T[2 * i + 2])
        elif s == "2":
            a = int(a) - 1
            b = int(b) - 1
            S = get(T, d, a, b + 1)
            print(len(S))


if __name__ == "__main__":
    main()
