class SegmentTree():
    def __init__(self,n):
        self.e = 0
        self.r = 0 #ノードの段数
        cnt = 0
        while cnt<n:
            cnt=2**self.r
            self.r +=1
        self.tree = [self.e]*(2**self.r -1)# 0-index
        self.n = 2**(self.r-1) #一番下のnodeの数
    def func(self,a,b): #適宜書き換え
        return a|b
    def update(self,i,val):
        i += self.n -1
        self.tree[i] = val
        while i>0:
            i = (i-1)//2
            self.tree[i] = self.func(self.tree[i*2+1],self.tree[i*2+2])

    def query(self,l,r):
        l += self.n -1
        r += self.n -1 #開区間 idxはr-1
        lval = self.e
        rval = self.e
        while r>l:
            if l%2 == 0:
                lval = self.func(lval,self.tree[l])
                l+=1
            if r%2==0:
                rval = self.func(rval,self.tree[r-1])
                r-=1
            r//=2
            l//=2
        return self.func(lval,rval)
    def index(self,i):
        return i+self.n -1
def sid(s):
    return ord(s)-ord("a") #chr("a") == 0

import sys
input = sys.stdin.readline
n = int(input())
S = input()[:-1]
Q = int(input())
seg = SegmentTree(n)
for i in range(n):
    s = S[i]
    seg.update(i,2**(sid(s)))
for q in range(Q):
    num,a,b = input().split()
    if num=="1":
        seg.update(int(a)-1,2**sid(b))
        #print(a,b,list(map(lambda x:bin(x)[2:],seg.tree)))
    else:
        print(bin(seg.query(int(a)-1,int(b))).count("1")) class SegmentTree():
    def __init__(self,n):
        self.e = 0
        self.r = 0 #ノードの段数
        cnt = 0
        while cnt<n:
            cnt=2**self.r
            self.r +=1
        self.tree = [self.e]*(2**self.r -1)# 0-index
        self.n = 2**(self.r-1) #一番下のnodeの数
    def func(self,a,b): #適宜書き換え
        return a|b
    def update(self,i,val):
        i += self.n -1
        self.tree[i] = val
        while i>0:
            i = (i-1)//2
            self.tree[i] = self.func(self.tree[i*2+1],self.tree[i*2+2])

    def query(self,l,r):
        l += self.n -1
        r += self.n -1 #開区間 idxはr-1
        lval = self.e
        rval = self.e
        while r>l:
            if l%2 == 0:
                lval = self.func(lval,self.tree[l])
                l+=1
            if r%2==0:
                rval = self.func(rval,self.tree[r-1])
                r-=1
            r//=2
            l//=2
        return self.func(lval,rval)
    def index(self,i):
        return i+self.n -1 SegmentTree def __init__(self,n):
        self.e = 0
        self.r = 0 #ノードの段数
        cnt = 0
        while cnt<n:
            cnt=2**self.r
            self.r +=1
        self.tree = [self.e]*(2**self.r -1)# 0-index
        self.n = 2**(self.r-1) #一番下のnodeの数
     __init__ self.e = 0 self.e self e 0 self.r = 0 self.r self r 0 cnt = 0 cnt 0 while cnt<n:
            cnt=2**self.r
            self.r +=1
         cnt<n cnt n cnt=2**self.r cnt 2**self.r 2 self.r self r self.r +=1 self.r self r 1 self.tree = [self.e]*(2**self.r -1) self.tree self tree [self.e]*(2**self.r -1) [self.e] self.e self e 2**self.r -1 2**self.r 2 self.r self r 1 self.n = 2**(self.r-1) self.n self n 2**(self.r-1) 2 self.r-1 self.r self r 1 self self n n def func(self,a,b): #適宜書き換え
        return a|b
     func return a|b a|b a b self self a a b b def update(self,i,val):
        i += self.n -1
        self.tree[i] = val
        while i>0:
            i = (i-1)//2
            self.tree[i] = self.func(self.tree[i*2+1],self.tree[i*2+2])

     update i += self.n -1 i self.n -1 self.n self n 1 self.tree[i] = val self.tree[i] self.tree self tree i val while i>0:
            i = (i-1)//2
            self.tree[i] = self.func(self.tree[i*2+1],self.tree[i*2+2])

     i>0 i 0 i = (i-1)//2 i (i-1)//2 i-1 i 1 2 self.tree[i] = self.func(self.tree[i*2+1],self.tree[i*2+2]) self.tree[i] self.tree self tree i self.func(self.tree[i*2+1],self.tree[i*2+2]) self.func self func self.tree[i*2+1] self.tree self tree i*2+1 i*2 i 2 1 self.tree[i*2+2] self.tree self tree i*2+2 i*2 i 2 2 self self i i val val def query(self,l,r):
        l += self.n -1
        r += self.n -1 #開区間 idxはr-1
        lval = self.e
        rval = self.e
        while r>l:
            if l%2 == 0:
                lval = self.func(lval,self.tree[l])
                l+=1
            if r%2==0:
                rval = self.func(rval,self.tree[r-1])
                r-=1
            r//=2
            l//=2
        return self.func(lval,rval)
     query l += self.n -1 l self.n -1 self.n self n 1 r += self.n -1 r self.n -1 self.n self n 1 lval = self.e lval self.e self e rval = self.e rval self.e self e while r>l:
            if l%2 == 0:
                lval = self.func(lval,self.tree[l])
                l+=1
            if r%2==0:
                rval = self.func(rval,self.tree[r-1])
                r-=1
            r//=2
            l//=2
         r>l r l if l%2 == 0:
                lval = self.func(lval,self.tree[l])
                l+=1
             l%2 == 0 l%2 l 2 0 lval = self.func(lval,self.tree[l]) lval self.func(lval,self.tree[l]) self.func self func lval self.tree[l] self.tree self tree l l+=1 l 1 if r%2==0:
                rval = self.func(rval,self.tree[r-1])
                r-=1
             r%2==0 r%2 r 2 0 rval = self.func(rval,self.tree[r-1]) rval self.func(rval,self.tree[r-1]) self.func self func rval self.tree[r-1] self.tree self tree r-1 r 1 r-=1 r 1 r//=2 r 2 l//=2 l 2 return self.func(lval,rval) self.func(lval,rval) self.func self func lval rval self self l l r r def index(self,i):
        return i+self.n -1 index return i+self.n -1 i+self.n -1 i+self.n i self.n self n 1 self self i i def sid(s):
    return ord(s)-ord("a") #chr("a") == 0 sid return ord(s)-ord("a") ord(s)-ord("a") ord(s) ord s ord("a") ord "a" s s import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n = int(input()) n int(input()) int input() input S = input()[:-1] S input()[:-1] () input :-1 -1 Q = int(input()) Q int(input()) int input() input seg = SegmentTree(n) seg SegmentTree(n) SegmentTree n for i in range(n):
    s = S[i]
    seg.update(i,2**(sid(s))) i range(n) range n s = S[i] s S[i] S i seg.update(i,2**(sid(s))) seg.update seg update i 2**(sid(s)) 2 sid(s) sid s for q in range(Q):
    num,a,b = input().split()
    if num=="1":
        seg.update(int(a)-1,2**sid(b))
        #print(a,b,list(map(lambda x:bin(x)[2:],seg.tree)))
    else:
        print(bin(seg.query(int(a)-1,int(b))).count("1")) q range(Q) range Q num,a,b = input().split() num input().split() ().split () input split a b if num=="1":
        seg.update(int(a)-1,2**sid(b))
        #print(a,b,list(map(lambda x:bin(x)[2:],seg.tree)))
    else:
        print(bin(seg.query(int(a)-1,int(b))).count("1")) num=="1" num "1" seg.update(int(a)-1,2**sid(b)) seg.update seg update int(a)-1 int(a) int a 1 2**sid(b) 2 sid(b) sid b print(bin(seg.query(int(a)-1,int(b))).count("1")) print bin(seg.query(int(a)-1,int(b))).count("1") (seg.query(int(a)-1,int(b))).count (seg.query(int(a)-1,int(b))) bin seg.query(int(a)-1,int(b)) seg.query seg query int(a)-1 int(a) int a 1 int(b) int b count "1" def sid(s):
    return ord(s)-ord("a") #chr("a") == 0 def sid(s):
    return ord(s)-ord("a") #chr("a") == 0 sid b = input().split() input().split() b seg = SegmentTree(n) SegmentTree(n) seg input = sys.stdin.readline sys.stdin.readline input s = S[i] S[i] s Q = int(input()) int(input()) Q S = input()[:-1] input()[:-1] S num,a,b = input().split() input().split() num class SegmentTree():
    def __init__(self,n):
        self.e = 0
        self.r = 0 #ノードの段数
        cnt = 0
        while cnt<n:
            cnt=2**self.r
            self.r +=1
        self.tree = [self.e]*(2**self.r -1)# 0-index
        self.n = 2**(self.r-1) #一番下のnodeの数
    def func(self,a,b): #適宜書き換え
        return a|b
    def update(self,i,val):
        i += self.n -1
        self.tree[i] = val
        while i>0:
            i = (i-1)//2
            self.tree[i] = self.func(self.tree[i*2+1],self.tree[i*2+2])

    def query(self,l,r):
        l += self.n -1
        r += self.n -1 #開区間 idxはr-1
        lval = self.e
        rval = self.e
        while r>l:
            if l%2 == 0:
                lval = self.func(lval,self.tree[l])
                l+=1
            if r%2==0:
                rval = self.func(rval,self.tree[r-1])
                r-=1
            r//=2
            l//=2
        return self.func(lval,rval)
    def index(self,i):
        return i+self.n -1 class SegmentTree():
    def __init__(self,n):
        self.e = 0
        self.r = 0 #ノードの段数
        cnt = 0
        while cnt<n:
            cnt=2**self.r
            self.r +=1
        self.tree = [self.e]*(2**self.r -1)# 0-index
        self.n = 2**(self.r-1) #一番下のnodeの数
    def func(self,a,b): #適宜書き換え
        return a|b
    def update(self,i,val):
        i += self.n -1
        self.tree[i] = val
        while i>0:
            i = (i-1)//2
            self.tree[i] = self.func(self.tree[i*2+1],self.tree[i*2+2])

    def query(self,l,r):
        l += self.n -1
        r += self.n -1 #開区間 idxはr-1
        lval = self.e
        rval = self.e
        while r>l:
            if l%2 == 0:
                lval = self.func(lval,self.tree[l])
                l+=1
            if r%2==0:
                rval = self.func(rval,self.tree[r-1])
                r-=1
            r//=2
            l//=2
        return self.func(lval,rval)
    def index(self,i):
        return i+self.n -1 SegmentTree n = int(input()) int(input()) n a,b = input().split() input().split() a
class SegmentTree():
    def __init__(self,n):
        self.e = 0
        self.r = 0 #ノードの段数
        cnt = 0
        while cnt<n:
            cnt=2**self.r
            self.r +=1
        self.tree = [self.e]*(2**self.r -1)# 0-index
        self.n = 2**(self.r-1) #一番下のnodeの数
    def func(self,a,b): #適宜書き換え
        return a|b
    def update(self,i,val):
        i += self.n -1
        self.tree[i] = val
        while i>0:
            i = (i-1)//2
            self.tree[i] = self.func(self.tree[i*2+1],self.tree[i*2+2])

    def query(self,l,r):
        l += self.n -1
        r += self.n -1 #開区間 idxはr-1
        lval = self.e
        rval = self.e
        while r>l:
            if l%2 == 0:
                lval = self.func(lval,self.tree[l])
                l+=1
            if r%2==0:
                rval = self.func(rval,self.tree[r-1])
                r-=1
            r//=2
            l//=2
        return self.func(lval,rval)
    def index(self,i):
        return i+self.n -1
def sid(s):
    return ord(s)-ord("a") #chr("a") == 0

import sys
input = sys.stdin.readline
n = int(input())
S = input()[:-1]
Q = int(input())
seg = SegmentTree(n)
for i in range(n):
    s = S[i]
    seg.update(i,2**(sid(s)))
for q in range(Q):
    num,a,b = input().split()
    if num=="1":
        seg.update(int(a)-1,2**sid(b))
        #print(a,b,list(map(lambda x:bin(x)[2:],seg.tree)))
    else:
        print(bin(seg.query(int(a)-1,int(b))).count("1"))
