import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


class Seg():
    def __init__(self, na, default, func):
        if isinstance(na, list):
            n = len(na)
        else:
            n = na
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        if isinstance(na, list):
            self.A = [default] * (self.N) + na + [default] * (self.N-n)
            for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
        else:
            self.A = [default] * (self.N*2)
        self.F = func

    def find(self, i):
        return self.A[i + self.N]

    def update(self, i, x):
        i += self.N
        self.A[i] = x
        while i > 1:
            i = i // 2
            self.A[i] = self.merge(self.A[i*2], self.A[i*2+1])

    def merge(self, a, b):
        return self.F(a, b)

    def total(self):
        return self.A[1]

    def query(self, a, b):
        A = self.A
        l = a + self.N
        r = b + self.N
        res = self.D
        while l < r:
            if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
            l >>= 1
            r >>= 1

        return res

def main():
    n = I()
    s = S()
    q = I()
    qa = [LS() for _ in range(q)]
    aa = [[0]*26]
    oa = ord('a')
    for c in s:
        t = [0] * 26
        t[ord(c) - oa] = 1
        aa.append(t)

    def f(a,b):
        return [a[i]+b[i] for i in range(26)]

    seg = Seg(aa,[0]*26,f)
    r = []
    for t,a,b in qa:
        if t == '1':
            u = [0] * 26
            u[ord(b) - oa] = 1
            seg.update(int(a),u)
        else:
            c = seg.query(0,int(a))
            d = seg.query(0,int(b)+1)
            r.append(len([1 for i in range(26) if c[i] != d[i]]))

    return JA(r, '\n')


print(main())


 import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools math string itertools fractions heapq collections re array bisect sys copy functools import time,random time random sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 inf = 10**20 inf 10**20 10 20 eps = 1.0 / 10**10 eps 1.0 / 10**10 1.0 10**10 10 10 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 mod2 = 998244353 mod2 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] dd [(-1,0),(0,1),(1,0),(0,-1)] (-1,0) -1 0 (0,1) 0 1 (1,0) 1 0 (0,-1) 0 -1 ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] ddn [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] (-1,0) -1 0 (-1,1) -1 1 (0,1) 0 1 (1,1) 1 1 (1,0) 1 0 (1,-1) 1 -1 (0,-1) 0 -1 (-1,-1) -1 -1 def LI(): return list(map(int, sys.stdin.readline().split())) LI list(map(int, l.split())) for l in sys.stdin.readlines() for l in sys.stdin.readlines() l sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines for l in sys.stdin.readlines() list(map(int, l.split())) list map(int, l.split()) map int l.split() l.split l split def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] LLI int(x)-1 for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x)-1 int(x) int x 1 def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] LI_ float(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() float(x) float x def LF(): return [float(x) for x in sys.stdin.readline().split()] LF def LS(): return sys.stdin.readline().split() LS def I(): return int(sys.stdin.readline()) I def F(): return float(sys.stdin.readline()) F def S(): return input() S def pf(s): return print(s, flush=True) pf s s def pe(s): return print(str(s), file=sys.stderr) pe s s def JA(a, sep): return sep.join(map(str, a)) JA a a sep sep def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) JAA a a s s t t class Seg():
    def __init__(self, na, default, func):
        if isinstance(na, list):
            n = len(na)
        else:
            n = na
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        if isinstance(na, list):
            self.A = [default] * (self.N) + na + [default] * (self.N-n)
            for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
        else:
            self.A = [default] * (self.N*2)
        self.F = func

    def find(self, i):
        return self.A[i + self.N]

    def update(self, i, x):
        i += self.N
        self.A[i] = x
        while i > 1:
            i = i // 2
            self.A[i] = self.merge(self.A[i*2], self.A[i*2+1])

    def merge(self, a, b):
        return self.F(a, b)

    def total(self):
        return self.A[1]

    def query(self, a, b):
        A = self.A
        l = a + self.N
        r = b + self.N
        res = self.D
        while l < r:
            if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
            l >>= 1
            r >>= 1

        return res Seg def __init__(self, na, default, func):
        if isinstance(na, list):
            n = len(na)
        else:
            n = na
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        if isinstance(na, list):
            self.A = [default] * (self.N) + na + [default] * (self.N-n)
            for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
        else:
            self.A = [default] * (self.N*2)
        self.F = func

     __init__ if isinstance(na, list):
            n = len(na)
        else:
            n = na
         isinstance(na, list) isinstance na list n = len(na) n len(na) len na n = na n na i = 1 i 1 while 2**i <= n:
            i += 1
         2**i <= n 2**i 2 i n i += 1 i 1 self.D = default self.D self D default self.H = i self.H self H i self.N = 2**i self.N self N 2**i 2 i if isinstance(na, list):
            self.A = [default] * (self.N) + na + [default] * (self.N-n)
            for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
        else:
            self.A = [default] * (self.N*2)
         isinstance(na, list) isinstance na list self.A = [default] * (self.N) + na + [default] * (self.N-n) self.A self A [default] * (self.N) + na + [default] * (self.N-n) [default] * (self.N) + na [default] * (self.N) [default] default self.N self N na [default] * (self.N-n) [default] default self.N-n self.N self N n for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
         i range(self.N-1,0,-1) range self.N-1 self.N self N 1 0 -1 self.A[i] = func(self.A[i*2], self.A[i*2+1]) self.A[i] self.A self A i func(self.A[i*2], self.A[i*2+1]) func self.A[i*2] self.A self A i*2 i 2 self.A[i*2+1] self.A self A i*2+1 i*2 i 2 1 self.A = [default] * (self.N*2) self.A self A [default] * (self.N*2) [default] default self.N*2 self.N self N 2 self.F = func self.F self F func self self na na default default func func def find(self, i):
        return self.A[i + self.N]

     find return self.A[i + self.N] self.A[i + self.N] self.A self A i + self.N i self.N self N self self i i def update(self, i, x):
        i += self.N
        self.A[i] = x
        while i > 1:
            i = i // 2
            self.A[i] = self.merge(self.A[i*2], self.A[i*2+1])

     update i += self.N i self.N self N self.A[i] = x self.A[i] self.A self A i x while i > 1:
            i = i // 2
            self.A[i] = self.merge(self.A[i*2], self.A[i*2+1])

     i > 1 i 1 i = i // 2 i i // 2 i 2 self.A[i] = self.merge(self.A[i*2], self.A[i*2+1]) self.A[i] self.A self A i self.merge(self.A[i*2], self.A[i*2+1]) self.merge self merge self.A[i*2] self.A self A i*2 i 2 self.A[i*2+1] self.A self A i*2+1 i*2 i 2 1 self self i i x x def merge(self, a, b):
        return self.F(a, b)

     merge return self.F(a, b) self.F(a, b) self.F self F a b self self a a b b def total(self):
        return self.A[1]

     total return self.A[1] self.A[1] self.A self A 1 self self def query(self, a, b):
        A = self.A
        l = a + self.N
        r = b + self.N
        res = self.D
        while l < r:
            if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
            l >>= 1
            r >>= 1

        return res query A = self.A A self.A self A l = a + self.N l a + self.N a self.N self N r = b + self.N r b + self.N b self.N self N res = self.D res self.D self D while l < r:
            if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
            l >>= 1
            r >>= 1

         l < r l r if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
             l % 2 == 1 l % 2 l 2 1 res = self.merge(res, A[l]) res self.merge(res, A[l]) self.merge self merge res A[l] A l l += 1 l 1 if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
             r % 2 == 1 r % 2 r 2 1 r -= 1 r 1 res = self.merge(res, A[r]) res self.merge(res, A[r]) self.merge self merge res A[r] A r l >>= 1 l 1 r >>= 1 r 1 return res res self self a a b b def main():
    n = I()
    s = S()
    q = I()
    qa = [LS() for _ in range(q)]
    aa = [[0]*26]
    oa = ord('a')
    for c in s:
        t = [0] * 26
        t[ord(c) - oa] = 1
        aa.append(t)

    def f(a,b):
        return [a[i]+b[i] for i in range(26)]

    seg = Seg(aa,[0]*26,f)
    r = []
    for t,a,b in qa:
        if t == '1':
            u = [0] * 26
            u[ord(b) - oa] = 1
            seg.update(int(a),u)
        else:
            c = seg.query(0,int(a))
            d = seg.query(0,int(b)+1)
            r.append(len([1 for i in range(26) if c[i] != d[i]]))

    return JA(r, '\n') main n = I() n I() I s = S() s S() S q = I() q I() I LS() for _ in range(q) for _ in range(q) _ range(q) range q for _ in range(q) LS() LS qa = [LS() for _ in range(q)] qa [LS() for _ in range(q)] aa = [[0]*26] aa [[0]*26] [0]*26 [0] 0 26 oa = ord('a') oa ord('a') ord 'a' for c in s:
        t = [0] * 26
        t[ord(c) - oa] = 1
        aa.append(t)

     c s t = [0] * 26 t [0] * 26 [0] 0 26 t[ord(c) - oa] = 1 t[ord(c) - oa] t ord(c) - oa ord(c) ord c oa 1 aa.append(t) aa.append aa append t def f(a,b):
        return [a[i]+b[i] for i in range(26)]

     f a[i]+b[i] for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) a[i]+b[i] a[i] a i b[i] b i return [a[i]+b[i] for i in range(26)] [a[i]+b[i] for i in range(26)] a a b b seg = Seg(aa,[0]*26,f) seg Seg(aa,[0]*26,f) Seg aa [0]*26 [0] 0 26 f r = [] r [] for t,a,b in qa:
        if t == '1':
            u = [0] * 26
            u[ord(b) - oa] = 1
            seg.update(int(a),u)
        else:
            c = seg.query(0,int(a))
            d = seg.query(0,int(b)+1)
            r.append(len([1 for i in range(26) if c[i] != d[i]]))

     t a b qa if t == '1':
            u = [0] * 26
            u[ord(b) - oa] = 1
            seg.update(int(a),u)
        else:
            c = seg.query(0,int(a))
            d = seg.query(0,int(b)+1)
            r.append(len([1 for i in range(26) if c[i] != d[i]]))

     t == '1' t '1' u = [0] * 26 u [0] * 26 [0] 0 26 u[ord(b) - oa] = 1 u[ord(b) - oa] u ord(b) - oa ord(b) ord b oa 1 seg.update(int(a),u) seg.update seg update int(a) int a u c = seg.query(0,int(a)) c seg.query(0,int(a)) seg.query seg query 0 int(a) int a d = seg.query(0,int(b)+1) d seg.query(0,int(b)+1) seg.query seg query 0 int(b)+1 int(b) int b 1 1 for i in range(26) if c[i] != d[i] for i in range(26) if c[i] != d[i] i range(26) range 26 c[i] != d[i] c[i] c i d[i] d i if c[i] != d[i] 1 r.append(len([1 for i in range(26) if c[i] != d[i]])) r.append r append len([1 for i in range(26) if c[i] != d[i]]) len [1 for i in range(26) if c[i] != d[i]] return JA(r, '\n') JA(r, '\n') JA r '\n' print(main()) print main() main inf = 10**20 10**20 inf mod2 = 998244353 998244353 mod2 def LS(): return sys.stdin.readline().split() def LS(): return sys.stdin.readline().split() LS def LF(): return [float(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] LF def pe(s): return print(str(s), file=sys.stderr) def pe(s): return print(str(s), file=sys.stderr) pe def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) JAA def main():
    n = I()
    s = S()
    q = I()
    qa = [LS() for _ in range(q)]
    aa = [[0]*26]
    oa = ord('a')
    for c in s:
        t = [0] * 26
        t[ord(c) - oa] = 1
        aa.append(t)

    def f(a,b):
        return [a[i]+b[i] for i in range(26)]

    seg = Seg(aa,[0]*26,f)
    r = []
    for t,a,b in qa:
        if t == '1':
            u = [0] * 26
            u[ord(b) - oa] = 1
            seg.update(int(a),u)
        else:
            c = seg.query(0,int(a))
            d = seg.query(0,int(b)+1)
            r.append(len([1 for i in range(26) if c[i] != d[i]]))

    return JA(r, '\n') def main():
    n = I()
    s = S()
    q = I()
    qa = [LS() for _ in range(q)]
    aa = [[0]*26]
    oa = ord('a')
    for c in s:
        t = [0] * 26
        t[ord(c) - oa] = 1
        aa.append(t)

    def f(a,b):
        return [a[i]+b[i] for i in range(26)]

    seg = Seg(aa,[0]*26,f)
    r = []
    for t,a,b in qa:
        if t == '1':
            u = [0] * 26
            u[ord(b) - oa] = 1
            seg.update(int(a),u)
        else:
            c = seg.query(0,int(a))
            d = seg.query(0,int(b)+1)
            r.append(len([1 for i in range(26) if c[i] != d[i]]))

    return JA(r, '\n') main def S(): return input() def S(): return input() S def LI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) LI def pf(s): return print(s, flush=True) def pf(s): return print(s, flush=True) pf dd = [(-1,0),(0,1),(1,0),(0,-1)] [(-1,0),(0,1),(1,0),(0,-1)] dd class Seg():
    def __init__(self, na, default, func):
        if isinstance(na, list):
            n = len(na)
        else:
            n = na
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        if isinstance(na, list):
            self.A = [default] * (self.N) + na + [default] * (self.N-n)
            for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
        else:
            self.A = [default] * (self.N*2)
        self.F = func

    def find(self, i):
        return self.A[i + self.N]

    def update(self, i, x):
        i += self.N
        self.A[i] = x
        while i > 1:
            i = i // 2
            self.A[i] = self.merge(self.A[i*2], self.A[i*2+1])

    def merge(self, a, b):
        return self.F(a, b)

    def total(self):
        return self.A[1]

    def query(self, a, b):
        A = self.A
        l = a + self.N
        r = b + self.N
        res = self.D
        while l < r:
            if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
            l >>= 1
            r >>= 1

        return res class Seg():
    def __init__(self, na, default, func):
        if isinstance(na, list):
            n = len(na)
        else:
            n = na
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        if isinstance(na, list):
            self.A = [default] * (self.N) + na + [default] * (self.N-n)
            for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
        else:
            self.A = [default] * (self.N*2)
        self.F = func

    def find(self, i):
        return self.A[i + self.N]

    def update(self, i, x):
        i += self.N
        self.A[i] = x
        while i > 1:
            i = i // 2
            self.A[i] = self.merge(self.A[i*2], self.A[i*2+1])

    def merge(self, a, b):
        return self.F(a, b)

    def total(self):
        return self.A[1]

    def query(self, a, b):
        A = self.A
        l = a + self.N
        r = b + self.N
        res = self.D
        while l < r:
            if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
            l >>= 1
            r >>= 1

        return res Seg def JA(a, sep): return sep.join(map(str, a)) def JA(a, sep): return sep.join(map(str, a)) JA def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] LI_ def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] LLI def F(): return float(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) F eps = 1.0 / 10**10 1.0 / 10**10 eps mod = 10**9+7 10**9+7 mod ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] ddn
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


class Seg():
    def __init__(self, na, default, func):
        if isinstance(na, list):
            n = len(na)
        else:
            n = na
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        if isinstance(na, list):
            self.A = [default] * (self.N) + na + [default] * (self.N-n)
            for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
        else:
            self.A = [default] * (self.N*2)
        self.F = func

    def find(self, i):
        return self.A[i + self.N]

    def update(self, i, x):
        i += self.N
        self.A[i] = x
        while i > 1:
            i = i // 2
            self.A[i] = self.merge(self.A[i*2], self.A[i*2+1])

    def merge(self, a, b):
        return self.F(a, b)

    def total(self):
        return self.A[1]

    def query(self, a, b):
        A = self.A
        l = a + self.N
        r = b + self.N
        res = self.D
        while l < r:
            if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
            l >>= 1
            r >>= 1

        return res

def main():
    n = I()
    s = S()
    q = I()
    qa = [LS() for _ in range(q)]
    aa = [[0]*26]
    oa = ord('a')
    for c in s:
        t = [0] * 26
        t[ord(c) - oa] = 1
        aa.append(t)

    def f(a,b):
        return [a[i]+b[i] for i in range(26)]

    seg = Seg(aa,[0]*26,f)
    r = []
    for t,a,b in qa:
        if t == '1':
            u = [0] * 26
            u[ord(b) - oa] = 1
            seg.update(int(a),u)
        else:
            c = seg.query(0,int(a))
            d = seg.query(0,int(b)+1)
            r.append(len([1 for i in range(26) if c[i] != d[i]]))

    return JA(r, '\n')


print(main())



