def RSQ_add(i, x, y):
    while True:
        if i > n:
            break
        BIT[y][i] += x
        i += i & -i

def RSQ_getsum(i, x):
    s = 0
    while True:
        if i <= 0:
            break
        s += BIT[x][i]
        i -= i & -i
    return s

n = int(input())
s = list(input())
q = int(input())
BIT = [[0] * (n + 1) for _ in range(26)]
for i in range(n):
    y = ord(s[i]) - 97
    RSQ_add(i + 1, 1, y)
for _ in range(q):
    com, a, b = map(str, input().split())
    com, a = int(com), int(a)
    if com == 1:
        RSQ_add(a, -1, ord(s[a - 1]) - 97)
        RSQ_add(a, 1, ord(b) - 97)
        s[a - 1] = b
    else:
        b = int(b)
        ans = 0
        for i in range(26):
            if RSQ_getsum(b, i) - RSQ_getsum(a - 1, i) >= 1:
                ans += 1
        print(ans) def RSQ_add(i, x, y):
    while True:
        if i > n:
            break
        BIT[y][i] += x
        i += i & -i RSQ_add while True:
        if i > n:
            break
        BIT[y][i] += x
        i += i & -i True if i > n:
            break
         i > n i n break BIT[y][i] += x BIT[y][i] [y] BIT y i x i += i & -i i i & -i i -i i i i x x y y def RSQ_getsum(i, x):
    s = 0
    while True:
        if i <= 0:
            break
        s += BIT[x][i]
        i -= i & -i
    return s RSQ_getsum s = 0 s 0 while True:
        if i <= 0:
            break
        s += BIT[x][i]
        i -= i & -i
     True if i <= 0:
            break
         i <= 0 i 0 break s += BIT[x][i] s BIT[x][i] [x] BIT x i i -= i & -i i i & -i i -i i return s s i i x x 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 [0] * (n + 1) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [0] * (n + 1) [0] 0 n + 1 n 1 BIT = [[0] * (n + 1) for _ in range(26)] BIT [[0] * (n + 1) for _ in range(26)] for i in range(n):
    y = ord(s[i]) - 97
    RSQ_add(i + 1, 1, y) i range(n) range n y = ord(s[i]) - 97 y ord(s[i]) - 97 ord(s[i]) ord s[i] s i 97 RSQ_add(i + 1, 1, y) RSQ_add i + 1 i 1 1 y for _ in range(q):
    com, a, b = map(str, input().split())
    com, a = int(com), int(a)
    if com == 1:
        RSQ_add(a, -1, ord(s[a - 1]) - 97)
        RSQ_add(a, 1, ord(b) - 97)
        s[a - 1] = b
    else:
        b = int(b)
        ans = 0
        for i in range(26):
            if RSQ_getsum(b, i) - RSQ_getsum(a - 1, i) >= 1:
                ans += 1
        print(ans) _ range(q) range q com, a, b = map(str, input().split()) com map(str, input().split()) map str input().split() ().split () input split a b com, a = int(com), int(a) com int(com) int com a int(a) int a if com == 1:
        RSQ_add(a, -1, ord(s[a - 1]) - 97)
        RSQ_add(a, 1, ord(b) - 97)
        s[a - 1] = b
    else:
        b = int(b)
        ans = 0
        for i in range(26):
            if RSQ_getsum(b, i) - RSQ_getsum(a - 1, i) >= 1:
                ans += 1
        print(ans) com == 1 com 1 RSQ_add(a, -1, ord(s[a - 1]) - 97) RSQ_add a -1 ord(s[a - 1]) - 97 ord(s[a - 1]) ord s[a - 1] s a - 1 a 1 97 RSQ_add(a, 1, ord(b) - 97) RSQ_add a 1 ord(b) - 97 ord(b) ord b 97 s[a - 1] = b s[a - 1] s a - 1 a 1 b b = int(b) b int(b) int b ans = 0 ans 0 for i in range(26):
            if RSQ_getsum(b, i) - RSQ_getsum(a - 1, i) >= 1:
                ans += 1
         i range(26) range 26 if RSQ_getsum(b, i) - RSQ_getsum(a - 1, i) >= 1:
                ans += 1
         RSQ_getsum(b, i) - RSQ_getsum(a - 1, i) >= 1 RSQ_getsum(b, i) - RSQ_getsum(a - 1, i) RSQ_getsum(b, i) RSQ_getsum b i RSQ_getsum(a - 1, i) RSQ_getsum a - 1 a 1 i 1 ans += 1 ans 1 print(ans) print ans def RSQ_getsum(i, x):
    s = 0
    while True:
        if i <= 0:
            break
        s += BIT[x][i]
        i -= i & -i
    return s def RSQ_getsum(i, x):
    s = 0
    while True:
        if i <= 0:
            break
        s += BIT[x][i]
        i -= i & -i
    return s RSQ_getsum a, b = map(str, input().split()) map(str, input().split()) a com, a, b = map(str, input().split()) map(str, input().split()) com def RSQ_add(i, x, y):
    while True:
        if i > n:
            break
        BIT[y][i] += x
        i += i & -i def RSQ_add(i, x, y):
    while True:
        if i > n:
            break
        BIT[y][i] += x
        i += i & -i RSQ_add ans += 1 1 ans b = int(b) int(b) b s = list(input()) list(input()) s com, a = int(com), int(a) int(com) com a = int(com), int(a) int(a) a n = int(input()) int(input()) n q = int(input()) int(input()) q ans = 0 0 ans b = map(str, input().split()) map(str, input().split()) b BIT = [[0] * (n + 1) for _ in range(26)] [[0] * (n + 1) for _ in range(26)] BIT y = ord(s[i]) - 97 ord(s[i]) - 97 y
def RSQ_add(i, x, y):
    while True:
        if i > n:
            break
        BIT[y][i] += x
        i += i & -i

def RSQ_getsum(i, x):
    s = 0
    while True:
        if i <= 0:
            break
        s += BIT[x][i]
        i -= i & -i
    return s

n = int(input())
s = list(input())
q = int(input())
BIT = [[0] * (n + 1) for _ in range(26)]
for i in range(n):
    y = ord(s[i]) - 97
    RSQ_add(i + 1, 1, y)
for _ in range(q):
    com, a, b = map(str, input().split())
    com, a = int(com), int(a)
    if com == 1:
        RSQ_add(a, -1, ord(s[a - 1]) - 97)
        RSQ_add(a, 1, ord(b) - 97)
        s[a - 1] = b
    else:
        b = int(b)
        ans = 0
        for i in range(26):
            if RSQ_getsum(b, i) - RSQ_getsum(a - 1, i) >= 1:
                ans += 1
        print(ans)