import sys
import bisect
import copy

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

cnt = [0] * 26
cumcnt = [cnt]

for i, s in enumerate(S):
    tmp = copy.copy(cumcnt[i])
    tmp[ord(s) - ord("a")] += 1
    cumcnt.append(tmp)

q_remove = {}
q_add = {}

for _ in range(Q):
    t, i, c = sys.stdin.readline().rstrip().split()
    t = int(t)
    i = int(i)
    d = S[i - 1]
    if t == 1:
        if d != c:
            if d not in q_remove.keys():
                q_remove[d] = [i]
            else:
                bisect.insort(q_remove[d], i)
            if c not in q_add.keys():
                q_add[c] = [i]
            else:
                bisect.insort(q_add[c], i)
            S[i - 1] = c 
    else:
        c = int(c)
        cnt_l = copy.copy(cumcnt[i - 1])
        cnt_r = copy.copy(cumcnt[c])
        for q, idx in q_add.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] += x
            cnt_r[ord(q) - ord("a")] += y
        for q, idx in q_remove.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] -= x
            cnt_r[ord(q) - ord("a")] -= y
        ans = 0
        for l, r in zip(cnt_l, cnt_r):
            if r - l > 0:
                ans += 1
        print(ans) import sys sys import bisect bisect import copy copy 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 = list(sys.stdin.readline().rstrip()) S list(sys.stdin.readline().rstrip()) list 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 cnt = [0] * 26 cnt [0] * 26 [0] 0 26 cumcnt = [cnt] cumcnt [cnt] cnt for i, s in enumerate(S):
    tmp = copy.copy(cumcnt[i])
    tmp[ord(s) - ord("a")] += 1
    cumcnt.append(tmp) i s enumerate(S) enumerate S tmp = copy.copy(cumcnt[i]) tmp copy.copy(cumcnt[i]) copy.copy copy copy cumcnt[i] cumcnt i tmp[ord(s) - ord("a")] += 1 tmp[ord(s) - ord("a")] tmp ord(s) - ord("a") ord(s) ord s ord("a") ord "a" 1 cumcnt.append(tmp) cumcnt.append cumcnt append tmp q_remove = {} q_remove {} q_add = {} q_add {} for _ in range(Q):
    t, i, c = sys.stdin.readline().rstrip().split()
    t = int(t)
    i = int(i)
    d = S[i - 1]
    if t == 1:
        if d != c:
            if d not in q_remove.keys():
                q_remove[d] = [i]
            else:
                bisect.insort(q_remove[d], i)
            if c not in q_add.keys():
                q_add[c] = [i]
            else:
                bisect.insort(q_add[c], i)
            S[i - 1] = c 
    else:
        c = int(c)
        cnt_l = copy.copy(cumcnt[i - 1])
        cnt_r = copy.copy(cumcnt[c])
        for q, idx in q_add.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] += x
            cnt_r[ord(q) - ord("a")] += y
        for q, idx in q_remove.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] -= x
            cnt_r[ord(q) - ord("a")] -= y
        ans = 0
        for l, r in zip(cnt_l, cnt_r):
            if r - l > 0:
                ans += 1
        print(ans) _ range(Q) range Q t, i, c = sys.stdin.readline().rstrip().split() t 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 i c t = int(t) t int(t) int t i = int(i) i int(i) int i d = S[i - 1] d S[i - 1] S i - 1 i 1 if t == 1:
        if d != c:
            if d not in q_remove.keys():
                q_remove[d] = [i]
            else:
                bisect.insort(q_remove[d], i)
            if c not in q_add.keys():
                q_add[c] = [i]
            else:
                bisect.insort(q_add[c], i)
            S[i - 1] = c 
    else:
        c = int(c)
        cnt_l = copy.copy(cumcnt[i - 1])
        cnt_r = copy.copy(cumcnt[c])
        for q, idx in q_add.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] += x
            cnt_r[ord(q) - ord("a")] += y
        for q, idx in q_remove.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] -= x
            cnt_r[ord(q) - ord("a")] -= y
        ans = 0
        for l, r in zip(cnt_l, cnt_r):
            if r - l > 0:
                ans += 1
        print(ans) t == 1 t 1 if d != c:
            if d not in q_remove.keys():
                q_remove[d] = [i]
            else:
                bisect.insort(q_remove[d], i)
            if c not in q_add.keys():
                q_add[c] = [i]
            else:
                bisect.insort(q_add[c], i)
            S[i - 1] = c 
     d != c d c if d not in q_remove.keys():
                q_remove[d] = [i]
            else:
                bisect.insort(q_remove[d], i)
             d not in q_remove.keys() d q_remove.keys() q_remove.keys q_remove keys q_remove[d] = [i] q_remove[d] q_remove d [i] i bisect.insort(q_remove[d], i) bisect.insort bisect insort q_remove[d] q_remove d i if c not in q_add.keys():
                q_add[c] = [i]
            else:
                bisect.insort(q_add[c], i)
             c not in q_add.keys() c q_add.keys() q_add.keys q_add keys q_add[c] = [i] q_add[c] q_add c [i] i bisect.insort(q_add[c], i) bisect.insort bisect insort q_add[c] q_add c i S[i - 1] = c S[i - 1] S i - 1 i 1 c c = int(c) c int(c) int c cnt_l = copy.copy(cumcnt[i - 1]) cnt_l copy.copy(cumcnt[i - 1]) copy.copy copy copy cumcnt[i - 1] cumcnt i - 1 i 1 cnt_r = copy.copy(cumcnt[c]) cnt_r copy.copy(cumcnt[c]) copy.copy copy copy cumcnt[c] cumcnt c for q, idx in q_add.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] += x
            cnt_r[ord(q) - ord("a")] += y
         q idx q_add.items() q_add.items q_add items x = bisect.bisect_right(idx, i - 1) x bisect.bisect_right(idx, i - 1) bisect.bisect_right bisect bisect_right idx i - 1 i 1 y = bisect.bisect_right(idx, c) y bisect.bisect_right(idx, c) bisect.bisect_right bisect bisect_right idx c cnt_l[ord(q) - ord("a")] += x cnt_l[ord(q) - ord("a")] cnt_l ord(q) - ord("a") ord(q) ord q ord("a") ord "a" x cnt_r[ord(q) - ord("a")] += y cnt_r[ord(q) - ord("a")] cnt_r ord(q) - ord("a") ord(q) ord q ord("a") ord "a" y for q, idx in q_remove.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] -= x
            cnt_r[ord(q) - ord("a")] -= y
         q idx q_remove.items() q_remove.items q_remove items x = bisect.bisect_right(idx, i - 1) x bisect.bisect_right(idx, i - 1) bisect.bisect_right bisect bisect_right idx i - 1 i 1 y = bisect.bisect_right(idx, c) y bisect.bisect_right(idx, c) bisect.bisect_right bisect bisect_right idx c cnt_l[ord(q) - ord("a")] -= x cnt_l[ord(q) - ord("a")] cnt_l ord(q) - ord("a") ord(q) ord q ord("a") ord "a" x cnt_r[ord(q) - ord("a")] -= y cnt_r[ord(q) - ord("a")] cnt_r ord(q) - ord("a") ord(q) ord q ord("a") ord "a" y ans = 0 ans 0 for l, r in zip(cnt_l, cnt_r):
            if r - l > 0:
                ans += 1
         l r zip(cnt_l, cnt_r) zip cnt_l cnt_r if r - l > 0:
                ans += 1
         r - l > 0 r - l r l 0 ans += 1 ans 1 print(ans) print ans ans = 0 0 ans c = int(c) int(c) c x = bisect.bisect_right(idx, i - 1) bisect.bisect_right(idx, i - 1) x y = bisect.bisect_right(idx, c) bisect.bisect_right(idx, c) y cnt_r = copy.copy(cumcnt[c]) copy.copy(cumcnt[c]) cnt_r t, i, c = sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split() t t = int(t) int(t) t q_add = {} {} q_add q_remove = {} {} q_remove tmp = copy.copy(cumcnt[i]) copy.copy(cumcnt[i]) tmp x = bisect.bisect_right(idx, i - 1) bisect.bisect_right(idx, i - 1) x i, c = sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split() i y = bisect.bisect_right(idx, c) bisect.bisect_right(idx, c) y N = int(sys.stdin.readline().rstrip()) int(sys.stdin.readline().rstrip()) N cnt = [0] * 26 [0] * 26 cnt c = sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split() c cumcnt = [cnt] [cnt] cumcnt d = S[i - 1] S[i - 1] d S = list(sys.stdin.readline().rstrip()) list(sys.stdin.readline().rstrip()) S Q = int(sys.stdin.readline().rstrip()) int(sys.stdin.readline().rstrip()) Q i = int(i) int(i) i cnt_l = copy.copy(cumcnt[i - 1]) copy.copy(cumcnt[i - 1]) cnt_l ans += 1 1 ans
import sys
import bisect
import copy

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

cnt = [0] * 26
cumcnt = [cnt]

for i, s in enumerate(S):
    tmp = copy.copy(cumcnt[i])
    tmp[ord(s) - ord("a")] += 1
    cumcnt.append(tmp)

q_remove = {}
q_add = {}

for _ in range(Q):
    t, i, c = sys.stdin.readline().rstrip().split()
    t = int(t)
    i = int(i)
    d = S[i - 1]
    if t == 1:
        if d != c:
            if d not in q_remove.keys():
                q_remove[d] = [i]
            else:
                bisect.insort(q_remove[d], i)
            if c not in q_add.keys():
                q_add[c] = [i]
            else:
                bisect.insort(q_add[c], i)
            S[i - 1] = c 
    else:
        c = int(c)
        cnt_l = copy.copy(cumcnt[i - 1])
        cnt_r = copy.copy(cumcnt[c])
        for q, idx in q_add.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] += x
            cnt_r[ord(q) - ord("a")] += y
        for q, idx in q_remove.items():
            x = bisect.bisect_right(idx, i - 1)
            y = bisect.bisect_right(idx, c)
            cnt_l[ord(q) - ord("a")] -= x
            cnt_r[ord(q) - ord("a")] -= y
        ans = 0
        for l, r in zip(cnt_l, cnt_r):
            if r - l > 0:
                ans += 1
        print(ans)