import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


class AVL_like_BIT:  # 1-indexed
    def __init__(self,n):  # 1~nを要素として持ちうる。
        self.n = n
        self.tree = [0]*(self.n+1)
        self.depth = n.bit_length()

    def add(self,k):  # kを木に加える
        while k<=self.n:
            self.tree[k]+=1
            k += k&-k
    
    def delete(self,k): # kを木から削除する
        while k<=self.n:
            self.tree[k]-=1
            k += k&-k

    def sum(self,k):  # 1~kの和
        ans = 0
        while k>0:
            ans += self.tree[k]
            k -= k&-k
        return ans
    
    def lower_bound(self,k):  # k以上の最小要素
        x = self.sum(k-1)
        if x == self.sum(self.n):  # k以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k-1)なるpの右端 + 1が答え
            q = p+v
            if q <= self.n and self.tree[q] <= x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

    def upper_bound(self,k):  # k以下の最大要素
        x = self.sum(k)
        if x == 0:  # k以下の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k)なるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

    def query(self,k):  # k番目の要素出力
        if k > self.sum(self.n):  # k個以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = kなるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < k:
                k -= self.tree[q]
                p += v
            v>>=1
        return p+1

a = ord('a')

n = readint()
s = [0] + [ord(x)-a for x in readstr()]
q = readint()

avl = [AVL_like_BIT(5*10**5 + 10) for i in range(26)]
for i in range(1,n+1):
    avl[s[i]].add(i)

ans = []
for i in range(q):
    j,l,r = readstrs()
    j = int(j)
    l = int(l)
    if j==1:
        avl[s[l]].delete(l)
        s[l] = ord(r)-a
        avl[s[l]].add(l)
    else:
        r = int(r)
        ans.append(0)
        for k in range(26):
            if avl[k].sum(l-1)-avl[k].sum(r):
                ans[-1]+=1

printrows(ans)





 import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline def readstr():return readline().rstrip().decode() readstr def readstrs():return list(readline().decode().split()) readstrs def readint():return int(readline()) readint def readints():return list(map(int,readline().split())) readints def printrows(x):print('\n'.join(map(str,x))) printrows x x def printline(x):print(' '.join(map(str,x))) printline x x class AVL_like_BIT:  # 1-indexed
    def __init__(self,n):  # 1~nを要素として持ちうる。
        self.n = n
        self.tree = [0]*(self.n+1)
        self.depth = n.bit_length()

    def add(self,k):  # kを木に加える
        while k<=self.n:
            self.tree[k]+=1
            k += k&-k
    
    def delete(self,k): # kを木から削除する
        while k<=self.n:
            self.tree[k]-=1
            k += k&-k

    def sum(self,k):  # 1~kの和
        ans = 0
        while k>0:
            ans += self.tree[k]
            k -= k&-k
        return ans
    
    def lower_bound(self,k):  # k以上の最小要素
        x = self.sum(k-1)
        if x == self.sum(self.n):  # k以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k-1)なるpの右端 + 1が答え
            q = p+v
            if q <= self.n and self.tree[q] <= x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

    def upper_bound(self,k):  # k以下の最大要素
        x = self.sum(k)
        if x == 0:  # k以下の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k)なるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

    def query(self,k):  # k番目の要素出力
        if k > self.sum(self.n):  # k個以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = kなるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < k:
                k -= self.tree[q]
                p += v
            v>>=1
        return p+1 AVL_like_BIT def __init__(self,n):  # 1~nを要素として持ちうる。
        self.n = n
        self.tree = [0]*(self.n+1)
        self.depth = n.bit_length()

     __init__ self.n = n self.n self n n self.tree = [0]*(self.n+1) self.tree self tree [0]*(self.n+1) [0] 0 self.n+1 self.n self n 1 self.depth = n.bit_length() self.depth self depth n.bit_length() n.bit_length n bit_length self self n n def add(self,k):  # kを木に加える
        while k<=self.n:
            self.tree[k]+=1
            k += k&-k
    
     add while k<=self.n:
            self.tree[k]+=1
            k += k&-k
    
     k<=self.n k self.n self n self.tree[k]+=1 self.tree[k] self.tree self tree k 1 k += k&-k k k&-k k -k k self self k k def delete(self,k): # kを木から削除する
        while k<=self.n:
            self.tree[k]-=1
            k += k&-k

     delete while k<=self.n:
            self.tree[k]-=1
            k += k&-k

     k<=self.n k self.n self n self.tree[k]-=1 self.tree[k] self.tree self tree k 1 k += k&-k k k&-k k -k k self self k k def sum(self,k):  # 1~kの和
        ans = 0
        while k>0:
            ans += self.tree[k]
            k -= k&-k
        return ans
    
     sum ans = 0 ans 0 while k>0:
            ans += self.tree[k]
            k -= k&-k
         k>0 k 0 ans += self.tree[k] ans self.tree[k] self.tree self tree k k -= k&-k k k&-k k -k k return ans ans self self k k def lower_bound(self,k):  # k以上の最小要素
        x = self.sum(k-1)
        if x == self.sum(self.n):  # k以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k-1)なるpの右端 + 1が答え
            q = p+v
            if q <= self.n and self.tree[q] <= x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

     lower_bound x = self.sum(k-1) x self.sum(k-1) self.sum self sum k-1 k 1 if x == self.sum(self.n):  # k以上の要素がないときは-1を返す
            return -1
         x == self.sum(self.n) x self.sum(self.n) self.sum self sum self.n self n return -1 -1 p = 0 p 0 v = 1<<self.depth v 1<<self.depth 1 self.depth self depth for i in range(self.depth + 1):  # sum(p) = sum(k-1)なるpの右端 + 1が答え
            q = p+v
            if q <= self.n and self.tree[q] <= x:
                x -= self.tree[q]
                p += v
            v>>=1
         i range(self.depth + 1) range self.depth + 1 self.depth self depth 1 q = p+v q p+v p v if q <= self.n and self.tree[q] <= x:
                x -= self.tree[q]
                p += v
             q <= self.n and self.tree[q] <= x q <= self.n q self.n self n self.tree[q] <= x self.tree[q] self.tree self tree q x x -= self.tree[q] x self.tree[q] self.tree self tree q p += v p v v>>=1 v 1 return p+1 p+1 p 1 self self k k def upper_bound(self,k):  # k以下の最大要素
        x = self.sum(k)
        if x == 0:  # k以下の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k)なるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

     upper_bound x = self.sum(k) x self.sum(k) self.sum self sum k if x == 0:  # k以下の要素がないときは-1を返す
            return -1
         x == 0 x 0 return -1 -1 p = 0 p 0 v = 1<<self.depth v 1<<self.depth 1 self.depth self depth for i in range(self.depth + 1):  # sum(p) = sum(k)なるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < x:
                x -= self.tree[q]
                p += v
            v>>=1
         i range(self.depth + 1) range self.depth + 1 self.depth self depth 1 q = p+v q p+v p v if q <= self.n and self.tree[q] < x:
                x -= self.tree[q]
                p += v
             q <= self.n and self.tree[q] < x q <= self.n q self.n self n self.tree[q] < x self.tree[q] self.tree self tree q x x -= self.tree[q] x self.tree[q] self.tree self tree q p += v p v v>>=1 v 1 return p+1 p+1 p 1 self self k k def query(self,k):  # k番目の要素出力
        if k > self.sum(self.n):  # k個以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = kなるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < k:
                k -= self.tree[q]
                p += v
            v>>=1
        return p+1 query if k > self.sum(self.n):  # k個以上の要素がないときは-1を返す
            return -1
         k > self.sum(self.n) k self.sum(self.n) self.sum self sum self.n self n return -1 -1 p = 0 p 0 v = 1<<self.depth v 1<<self.depth 1 self.depth self depth for i in range(self.depth + 1):  # sum(p) = kなるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < k:
                k -= self.tree[q]
                p += v
            v>>=1
         i range(self.depth + 1) range self.depth + 1 self.depth self depth 1 q = p+v q p+v p v if q <= self.n and self.tree[q] < k:
                k -= self.tree[q]
                p += v
             q <= self.n and self.tree[q] < k q <= self.n q self.n self n self.tree[q] < k self.tree[q] self.tree self tree q k k -= self.tree[q] k self.tree[q] self.tree self tree q p += v p v v>>=1 v 1 return p+1 p+1 p 1 self self k k a = ord('a') a ord('a') ord 'a' n = readint() n readint() readint ord(x)-a for x in readstr() for x in readstr() x readstr() readstr for x in readstr() ord(x)-a ord(x) ord x a s = [0] + [ord(x)-a for x in readstr()] s [0] + [ord(x)-a for x in readstr()] [0] 0 [ord(x)-a for x in readstr()] q = readint() q readint() readint AVL_like_BIT(5*10**5 + 10) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) AVL_like_BIT(5*10**5 + 10) AVL_like_BIT 5*10**5 + 10 5*10**5 5 10**5 10 5 10 avl = [AVL_like_BIT(5*10**5 + 10) for i in range(26)] avl [AVL_like_BIT(5*10**5 + 10) for i in range(26)] for i in range(1,n+1):
    avl[s[i]].add(i) i range(1,n+1) range 1 n+1 n 1 avl[s[i]].add(i) [s[i]].add [s[i]] avl s[i] s i add i ans = [] ans [] for i in range(q):
    j,l,r = readstrs()
    j = int(j)
    l = int(l)
    if j==1:
        avl[s[l]].delete(l)
        s[l] = ord(r)-a
        avl[s[l]].add(l)
    else:
        r = int(r)
        ans.append(0)
        for k in range(26):
            if avl[k].sum(l-1)-avl[k].sum(r):
                ans[-1]+=1 i range(q) range q j,l,r = readstrs() j readstrs() readstrs l r j = int(j) j int(j) int j l = int(l) l int(l) int l if j==1:
        avl[s[l]].delete(l)
        s[l] = ord(r)-a
        avl[s[l]].add(l)
    else:
        r = int(r)
        ans.append(0)
        for k in range(26):
            if avl[k].sum(l-1)-avl[k].sum(r):
                ans[-1]+=1 j==1 j 1 avl[s[l]].delete(l) [s[l]].delete [s[l]] avl s[l] s l delete l s[l] = ord(r)-a s[l] s l ord(r)-a ord(r) ord r a avl[s[l]].add(l) [s[l]].add [s[l]] avl s[l] s l add l r = int(r) r int(r) int r ans.append(0) ans.append ans append 0 for k in range(26):
            if avl[k].sum(l-1)-avl[k].sum(r):
                ans[-1]+=1 k range(26) range 26 if avl[k].sum(l-1)-avl[k].sum(r):
                ans[-1]+=1 avl[k].sum(l-1)-avl[k].sum(r) avl[k].sum(l-1) [k].sum [k] avl k sum l-1 l 1 avl[k].sum(r) [k].sum [k] avl k sum r ans[-1]+=1 ans[-1] ans -1 1 printrows(ans) printrows ans r = int(r) int(r) r ans = [] [] ans avl = [AVL_like_BIT(5*10**5 + 10) for i in range(26)] [AVL_like_BIT(5*10**5 + 10) for i in range(26)] avl def readints():return list(map(int,readline().split())) def readints():return list(map(int,readline().split())) readints a = ord('a') ord('a') a q = readint() readint() q def printline(x):print(' '.join(map(str,x))) def printline(x):print(' '.join(map(str,x))) printline def readstr():return readline().rstrip().decode() def readstr():return readline().rstrip().decode() readstr j,l,r = readstrs() readstrs() j def printrows(x):print('\n'.join(map(str,x))) def printrows(x):print('\n'.join(map(str,x))) printrows l = int(l) int(l) l def readint():return int(readline()) def readint():return int(readline()) readint def readstrs():return list(readline().decode().split()) def readstrs():return list(readline().decode().split()) readstrs readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline r = readstrs() readstrs() r j = int(j) int(j) j class AVL_like_BIT:  # 1-indexed
    def __init__(self,n):  # 1~nを要素として持ちうる。
        self.n = n
        self.tree = [0]*(self.n+1)
        self.depth = n.bit_length()

    def add(self,k):  # kを木に加える
        while k<=self.n:
            self.tree[k]+=1
            k += k&-k
    
    def delete(self,k): # kを木から削除する
        while k<=self.n:
            self.tree[k]-=1
            k += k&-k

    def sum(self,k):  # 1~kの和
        ans = 0
        while k>0:
            ans += self.tree[k]
            k -= k&-k
        return ans
    
    def lower_bound(self,k):  # k以上の最小要素
        x = self.sum(k-1)
        if x == self.sum(self.n):  # k以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k-1)なるpの右端 + 1が答え
            q = p+v
            if q <= self.n and self.tree[q] <= x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

    def upper_bound(self,k):  # k以下の最大要素
        x = self.sum(k)
        if x == 0:  # k以下の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k)なるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

    def query(self,k):  # k番目の要素出力
        if k > self.sum(self.n):  # k個以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = kなるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < k:
                k -= self.tree[q]
                p += v
            v>>=1
        return p+1 class AVL_like_BIT:  # 1-indexed
    def __init__(self,n):  # 1~nを要素として持ちうる。
        self.n = n
        self.tree = [0]*(self.n+1)
        self.depth = n.bit_length()

    def add(self,k):  # kを木に加える
        while k<=self.n:
            self.tree[k]+=1
            k += k&-k
    
    def delete(self,k): # kを木から削除する
        while k<=self.n:
            self.tree[k]-=1
            k += k&-k

    def sum(self,k):  # 1~kの和
        ans = 0
        while k>0:
            ans += self.tree[k]
            k -= k&-k
        return ans
    
    def lower_bound(self,k):  # k以上の最小要素
        x = self.sum(k-1)
        if x == self.sum(self.n):  # k以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k-1)なるpの右端 + 1が答え
            q = p+v
            if q <= self.n and self.tree[q] <= x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

    def upper_bound(self,k):  # k以下の最大要素
        x = self.sum(k)
        if x == 0:  # k以下の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k)なるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

    def query(self,k):  # k番目の要素出力
        if k > self.sum(self.n):  # k個以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = kなるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < k:
                k -= self.tree[q]
                p += v
            v>>=1
        return p+1 AVL_like_BIT s = [0] + [ord(x)-a for x in readstr()] [0] + [ord(x)-a for x in readstr()] s l,r = readstrs() readstrs() l n = readint() readint() n
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


class AVL_like_BIT:  # 1-indexed
    def __init__(self,n):  # 1~nを要素として持ちうる。
        self.n = n
        self.tree = [0]*(self.n+1)
        self.depth = n.bit_length()

    def add(self,k):  # kを木に加える
        while k<=self.n:
            self.tree[k]+=1
            k += k&-k
    
    def delete(self,k): # kを木から削除する
        while k<=self.n:
            self.tree[k]-=1
            k += k&-k

    def sum(self,k):  # 1~kの和
        ans = 0
        while k>0:
            ans += self.tree[k]
            k -= k&-k
        return ans
    
    def lower_bound(self,k):  # k以上の最小要素
        x = self.sum(k-1)
        if x == self.sum(self.n):  # k以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k-1)なるpの右端 + 1が答え
            q = p+v
            if q <= self.n and self.tree[q] <= x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

    def upper_bound(self,k):  # k以下の最大要素
        x = self.sum(k)
        if x == 0:  # k以下の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = sum(k)なるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < x:
                x -= self.tree[q]
                p += v
            v>>=1
        return p+1

    def query(self,k):  # k番目の要素出力
        if k > self.sum(self.n):  # k個以上の要素がないときは-1を返す
            return -1
        p = 0
        v = 1<<self.depth
        for i in range(self.depth + 1):  # sum(p) = kなるpの左端が答え
            q = p+v
            if q <= self.n and self.tree[q] < k:
                k -= self.tree[q]
                p += v
            v>>=1
        return p+1

a = ord('a')

n = readint()
s = [0] + [ord(x)-a for x in readstr()]
q = readint()

avl = [AVL_like_BIT(5*10**5 + 10) for i in range(26)]
for i in range(1,n+1):
    avl[s[i]].add(i)

ans = []
for i in range(q):
    j,l,r = readstrs()
    j = int(j)
    l = int(l)
    if j==1:
        avl[s[l]].delete(l)
        s[l] = ord(r)-a
        avl[s[l]].add(l)
    else:
        r = int(r)
        ans.append(0)
        for k in range(26):
            if avl[k].sum(l-1)-avl[k].sum(r):
                ans[-1]+=1

printrows(ans)






