import sys
# from collections import defaultdict

N = int(sys.stdin.readline().rstrip())
S = sys.stdin.readline().rstrip()
Q = int(sys.stdin.readline().rstrip())

BIT = [[0 for _ in range(N + 1)] for _ in range(26)]  # 初期化（アルファベット分）
alpha = {"a": 0, "b": 1, "c": 2, "d": 3, "e": 4,
         "f": 5, "g": 6, "h": 7, "i": 8, "j": 9,
         "k": 10, "l": 11, "m": 12, "n": 13, "o": 14,
         "p": 15, "q": 16, "r": 17, "s": 18, "t": 19,
         "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25}


# 初期化
def initialize():
    global BIT, S, N
    for j in range(N):
        c = alpha[S[j]]  # 文字切り出し／index に変換
        i = j + 1
        while i <= N:
            BIT[c][i] += 1
            i += (i & -i)


def identify(i):
    # i文字目を、変化点があった文字として探索する
    for c in range(26):
        if sum(i, c) != sum(i - 1, c):
            return c


# 文字の交換
def change(i, before, after):

    global BIT, N
    while i <= N:
        BIT[before][i] -= 1
        BIT[after][i] += 1
        i += (i & -i)


# 文字数の取り出し
def sum(i, c):

    global BIT

    _sum = 0
    while i > 0:
        _sum += BIT[c][i]
        i -= (i & -i)

    return _sum


initialize()

for _ in range(Q):
    q, x, y = sys.stdin.readline().rstrip().split()
    if q == "1":
        i = int(x)
        ac = alpha[y]
        bc = identify(i)
        change(i, bc, ac)

    else:
        x = int(x)
        y = int(y)
        count = 0
        for c in range(26):
            if sum(y, c) != sum(x - 1, c):
                count += 1
        print(count) import sys sys N = int(sys.stdin.readline().rstrip()) N int(sys.stdin.readline().rstrip()) int sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip S = sys.stdin.readline().rstrip() S sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip Q = int(sys.stdin.readline().rstrip()) Q int(sys.stdin.readline().rstrip()) int sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip [0 for _ in range(N + 1)] for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [0 for _ in range(N + 1)] BIT = [[0 for _ in range(N + 1)] for _ in range(26)] BIT [[0 for _ in range(N + 1)] for _ in range(26)] alpha = {"a": 0, "b": 1, "c": 2, "d": 3, "e": 4,
         "f": 5, "g": 6, "h": 7, "i": 8, "j": 9,
         "k": 10, "l": 11, "m": 12, "n": 13, "o": 14,
         "p": 15, "q": 16, "r": 17, "s": 18, "t": 19,
         "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25} alpha {"a": 0, "b": 1, "c": 2, "d": 3, "e": 4,
         "f": 5, "g": 6, "h": 7, "i": 8, "j": 9,
         "k": 10, "l": 11, "m": 12, "n": 13, "o": 14,
         "p": 15, "q": 16, "r": 17, "s": 18, "t": 19,
         "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25} "a" "a" 0 "b" "b" 1 "c" "c" 2 "d" "d" 3 "e" "e" 4 "f" "f" 5 "g" "g" 6 "h" "h" 7 "i" "i" 8 "j" "j" 9 "k" "k" 10 "l" "l" 11 "m" "m" 12 "n" "n" 13 "o" "o" 14 "p" "p" 15 "q" "q" 16 "r" "r" 17 "s" "s" 18 "t" "t" 19 "u" "u" 20 "v" "v" 21 "w" "w" 22 "x" "x" 23 "y" "y" 24 "z" "z" 25 def initialize():
    global BIT, S, N
    for j in range(N):
        c = alpha[S[j]]  # 文字切り出し／index に変換
        i = j + 1
        while i <= N:
            BIT[c][i] += 1
            i += (i & -i) initialize global BIT, S, N for j in range(N):
        c = alpha[S[j]]  # 文字切り出し／index に変換
        i = j + 1
        while i <= N:
            BIT[c][i] += 1
            i += (i & -i) j range(N) range N c = alpha[S[j]] c alpha[S[j]] alpha S[j] S j i = j + 1 i j + 1 j 1 while i <= N:
            BIT[c][i] += 1
            i += (i & -i) i <= N i N BIT[c][i] += 1 BIT[c][i] [c] BIT c i 1 i += (i & -i) i i & -i i -i i def identify(i):
    # i文字目を、変化点があった文字として探索する
    for c in range(26):
        if sum(i, c) != sum(i - 1, c):
            return c


# 文字の交換 identify for c in range(26):
        if sum(i, c) != sum(i - 1, c):
            return c


# 文字の交換 c range(26) range 26 if sum(i, c) != sum(i - 1, c):
            return c


# 文字の交換 sum(i, c) != sum(i - 1, c) sum(i, c) sum i c sum(i - 1, c) sum i - 1 i 1 c return c c i i def change(i, before, after):

    global BIT, N
    while i <= N:
        BIT[before][i] -= 1
        BIT[after][i] += 1
        i += (i & -i)


# 文字数の取り出し change global BIT, N while i <= N:
        BIT[before][i] -= 1
        BIT[after][i] += 1
        i += (i & -i)


# 文字数の取り出し i <= N i N BIT[before][i] -= 1 BIT[before][i] [before] BIT before i 1 BIT[after][i] += 1 BIT[after][i] [after] BIT after i 1 i += (i & -i) i i & -i i -i i i i before before after after def sum(i, c):

    global BIT

    _sum = 0
    while i > 0:
        _sum += BIT[c][i]
        i -= (i & -i)

    return _sum sum global BIT _sum = 0 _sum 0 while i > 0:
        _sum += BIT[c][i]
        i -= (i & -i)

     i > 0 i 0 _sum += BIT[c][i] _sum BIT[c][i] [c] BIT c i i -= (i & -i) i i & -i i -i i return _sum _sum i i c c initialize() initialize for _ in range(Q):
    q, x, y = sys.stdin.readline().rstrip().split()
    if q == "1":
        i = int(x)
        ac = alpha[y]
        bc = identify(i)
        change(i, bc, ac)

    else:
        x = int(x)
        y = int(y)
        count = 0
        for c in range(26):
            if sum(y, c) != sum(x - 1, c):
                count += 1
        print(count) _ range(Q) range Q q, x, y = sys.stdin.readline().rstrip().split() q sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip split x y if q == "1":
        i = int(x)
        ac = alpha[y]
        bc = identify(i)
        change(i, bc, ac)

    else:
        x = int(x)
        y = int(y)
        count = 0
        for c in range(26):
            if sum(y, c) != sum(x - 1, c):
                count += 1
        print(count) q == "1" q "1" i = int(x) i int(x) int x ac = alpha[y] ac alpha[y] alpha y bc = identify(i) bc identify(i) identify i change(i, bc, ac) change i bc ac x = int(x) x int(x) int x y = int(y) y int(y) int y count = 0 count 0 for c in range(26):
            if sum(y, c) != sum(x - 1, c):
                count += 1
         c range(26) range 26 if sum(y, c) != sum(x - 1, c):
                count += 1
         sum(y, c) != sum(x - 1, c) sum(y, c) sum y c sum(x - 1, c) sum x - 1 x 1 c count += 1 count 1 print(count) print count alpha = {"a": 0, "b": 1, "c": 2, "d": 3, "e": 4,
         "f": 5, "g": 6, "h": 7, "i": 8, "j": 9,
         "k": 10, "l": 11, "m": 12, "n": 13, "o": 14,
         "p": 15, "q": 16, "r": 17, "s": 18, "t": 19,
         "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25} {"a": 0, "b": 1, "c": 2, "d": 3, "e": 4,
         "f": 5, "g": 6, "h": 7, "i": 8, "j": 9,
         "k": 10, "l": 11, "m": 12, "n": 13, "o": 14,
         "p": 15, "q": 16, "r": 17, "s": 18, "t": 19,
         "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25} alpha i = int(x) int(x) i count = 0 0 count bc = identify(i) identify(i) bc S = sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() S ac = alpha[y] alpha[y] ac y = sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split() y x = int(x) int(x) x def sum(i, c):

    global BIT

    _sum = 0
    while i > 0:
        _sum += BIT[c][i]
        i -= (i & -i)

    return _sum def sum(i, c):

    global BIT

    _sum = 0
    while i > 0:
        _sum += BIT[c][i]
        i -= (i & -i)

    return _sum sum def identify(i):
    # i文字目を、変化点があった文字として探索する
    for c in range(26):
        if sum(i, c) != sum(i - 1, c):
            return c


# 文字の交換 def identify(i):
    # i文字目を、変化点があった文字として探索する
    for c in range(26):
        if sum(i, c) != sum(i - 1, c):
            return c


# 文字の交換 identify def change(i, before, after):

    global BIT, N
    while i <= N:
        BIT[before][i] -= 1
        BIT[after][i] += 1
        i += (i & -i)


# 文字数の取り出し def change(i, before, after):

    global BIT, N
    while i <= N:
        BIT[before][i] -= 1
        BIT[after][i] += 1
        i += (i & -i)


# 文字数の取り出し change N = int(sys.stdin.readline().rstrip()) int(sys.stdin.readline().rstrip()) N count += 1 1 count def initialize():
    global BIT, S, N
    for j in range(N):
        c = alpha[S[j]]  # 文字切り出し／index に変換
        i = j + 1
        while i <= N:
            BIT[c][i] += 1
            i += (i & -i) def initialize():
    global BIT, S, N
    for j in range(N):
        c = alpha[S[j]]  # 文字切り出し／index に変換
        i = j + 1
        while i <= N:
            BIT[c][i] += 1
            i += (i & -i) initialize y = int(y) int(y) y BIT = [[0 for _ in range(N + 1)] for _ in range(26)] [[0 for _ in range(N + 1)] for _ in range(26)] BIT x, y = sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split() x q, x, y = sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split() q Q = int(sys.stdin.readline().rstrip()) int(sys.stdin.readline().rstrip()) Q
import sys
# from collections import defaultdict

N = int(sys.stdin.readline().rstrip())
S = sys.stdin.readline().rstrip()
Q = int(sys.stdin.readline().rstrip())

BIT = [[0 for _ in range(N + 1)] for _ in range(26)]  # 初期化（アルファベット分）
alpha = {"a": 0, "b": 1, "c": 2, "d": 3, "e": 4,
         "f": 5, "g": 6, "h": 7, "i": 8, "j": 9,
         "k": 10, "l": 11, "m": 12, "n": 13, "o": 14,
         "p": 15, "q": 16, "r": 17, "s": 18, "t": 19,
         "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25}


# 初期化
def initialize():
    global BIT, S, N
    for j in range(N):
        c = alpha[S[j]]  # 文字切り出し／index に変換
        i = j + 1
        while i <= N:
            BIT[c][i] += 1
            i += (i & -i)


def identify(i):
    # i文字目を、変化点があった文字として探索する
    for c in range(26):
        if sum(i, c) != sum(i - 1, c):
            return c


# 文字の交換
def change(i, before, after):

    global BIT, N
    while i <= N:
        BIT[before][i] -= 1
        BIT[after][i] += 1
        i += (i & -i)


# 文字数の取り出し
def sum(i, c):

    global BIT

    _sum = 0
    while i > 0:
        _sum += BIT[c][i]
        i -= (i & -i)

    return _sum


initialize()

for _ in range(Q):
    q, x, y = sys.stdin.readline().rstrip().split()
    if q == "1":
        i = int(x)
        ac = alpha[y]
        bc = identify(i)
        change(i, bc, ac)

    else:
        x = int(x)
        y = int(y)
        count = 0
        for c in range(26):
            if sum(y, c) != sum(x - 1, c):
                count += 1
        print(count)