class SegT():
    def __init__(self, size):
        self.size = 1
        while self.size < size: self.size *= 2
        self.data = [0] * (self.size * 2 - 1)
    
    def update(self, i, x):
        i += (self.size - 1)
        self.data[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.data[i] = self.data[i*2+1] | self.data[i*2+2]
        
    def get(self, a, b, node=0, l=0, r=-1):
        if r < 0: r = self.size
        if r <= a or b <= l: return 0
        if a <= l and r <= b: return self.data[node]
        vl = self.get(a, b, node*2+1, l, (l+r)//2)
        vr = self.get(a, b, node*2+2, (l+r)//2, r)
        return vl | vr

N = int(input())
S = input()
Q = int(input())

segt = SegT(N)
for i in range(N):
    x = ord(S[i]) - ord('a')
    segt.update(i, (1<<x))

for i in range(Q):
    t, l, r = input().split()
    if t == "1":
        x = ord(r) - ord('a')
        segt.update(int(l)-1, (1<<x))
    else:
        x = segt.get(int(l)-1,int(r))
        ans = 0
        for i in range(26):
            if x>>i&1: ans += 1
        print(ans) class SegT():
    def __init__(self, size):
        self.size = 1
        while self.size < size: self.size *= 2
        self.data = [0] * (self.size * 2 - 1)
    
    def update(self, i, x):
        i += (self.size - 1)
        self.data[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.data[i] = self.data[i*2+1] | self.data[i*2+2]
        
    def get(self, a, b, node=0, l=0, r=-1):
        if r < 0: r = self.size
        if r <= a or b <= l: return 0
        if a <= l and r <= b: return self.data[node]
        vl = self.get(a, b, node*2+1, l, (l+r)//2)
        vr = self.get(a, b, node*2+2, (l+r)//2, r)
        return vl | vr SegT def __init__(self, size):
        self.size = 1
        while self.size < size: self.size *= 2
        self.data = [0] * (self.size * 2 - 1)
    
     __init__ self.size = 1 self.size self size 1 while self.size < size: self.size *= 2
         self.size < size self.size self size size self.data = [0] * (self.size * 2 - 1) self.data self data [0] * (self.size * 2 - 1) [0] 0 self.size * 2 - 1 self.size * 2 self.size self size 2 1 self self size size def update(self, i, x):
        i += (self.size - 1)
        self.data[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.data[i] = self.data[i*2+1] | self.data[i*2+2]
        
     update i += (self.size - 1) i self.size - 1 self.size self size 1 self.data[i] = x self.data[i] self.data self data i x while i > 0:
            i = (i - 1) // 2
            self.data[i] = self.data[i*2+1] | self.data[i*2+2]
        
     i > 0 i 0 i = (i - 1) // 2 i (i - 1) // 2 i - 1 i 1 2 self.data[i] = self.data[i*2+1] | self.data[i*2+2] self.data[i] self.data self data i self.data[i*2+1] | self.data[i*2+2] self.data[i*2+1] self.data self data i*2+1 i*2 i 2 1 self.data[i*2+2] self.data self data i*2+2 i*2 i 2 2 self self i i x x def get(self, a, b, node=0, l=0, r=-1):
        if r < 0: r = self.size
        if r <= a or b <= l: return 0
        if a <= l and r <= b: return self.data[node]
        vl = self.get(a, b, node*2+1, l, (l+r)//2)
        vr = self.get(a, b, node*2+2, (l+r)//2, r)
        return vl | vr get if r < 0: r = self.size
         r < 0 r 0 if r <= a or b <= l: return 0
         r <= a or b <= l r <= a r a b <= l b l if a <= l and r <= b: return self.data[node]
         a <= l and r <= b a <= l a l r <= b r b vl = self.get(a, b, node*2+1, l, (l+r)//2) vl self.get(a, b, node*2+1, l, (l+r)//2) self.get self get a b node*2+1 node*2 node 2 1 l (l+r)//2 l+r l r 2 vr = self.get(a, b, node*2+2, (l+r)//2, r) vr self.get(a, b, node*2+2, (l+r)//2, r) self.get self get a b node*2+2 node*2 node 2 2 (l+r)//2 l+r l r 2 r return vl | vr vl | vr vl vr self self a a b b node=0 node 0 l=0 l 0 r=-1 r -1 N = int(input()) N int(input()) int input() input S = input() S input() input Q = int(input()) Q int(input()) int input() input segt = SegT(N) segt SegT(N) SegT N for i in range(N):
    x = ord(S[i]) - ord('a')
    segt.update(i, (1<<x)) i range(N) range N x = ord(S[i]) - ord('a') x ord(S[i]) - ord('a') ord(S[i]) ord S[i] S i ord('a') ord 'a' segt.update(i, (1<<x)) segt.update segt update i 1<<x 1 x for i in range(Q):
    t, l, r = input().split()
    if t == "1":
        x = ord(r) - ord('a')
        segt.update(int(l)-1, (1<<x))
    else:
        x = segt.get(int(l)-1,int(r))
        ans = 0
        for i in range(26):
            if x>>i&1: ans += 1
        print(ans) i range(Q) range Q t, l, r = input().split() t input().split() ().split () input split l r if t == "1":
        x = ord(r) - ord('a')
        segt.update(int(l)-1, (1<<x))
    else:
        x = segt.get(int(l)-1,int(r))
        ans = 0
        for i in range(26):
            if x>>i&1: ans += 1
        print(ans) t == "1" t "1" x = ord(r) - ord('a') x ord(r) - ord('a') ord(r) ord r ord('a') ord 'a' segt.update(int(l)-1, (1<<x)) segt.update segt update int(l)-1 int(l) int l 1 1<<x 1 x x = segt.get(int(l)-1,int(r)) x segt.get(int(l)-1,int(r)) segt.get segt get int(l)-1 int(l) int l 1 int(r) int r ans = 0 ans 0 for i in range(26):
            if x>>i&1: ans += 1
         i range(26) range 26 if x>>i&1: ans += 1
         x>>i&1 x>>i x i 1 print(ans) print ans N = int(input()) int(input()) N ans = 0 0 ans segt = SegT(N) SegT(N) segt x = ord(r) - ord('a') ord(r) - ord('a') x S = input() input() S Q = int(input()) int(input()) Q l, r = input().split() input().split() l x = segt.get(int(l)-1,int(r)) segt.get(int(l)-1,int(r)) x t, l, r = input().split() input().split() t class SegT():
    def __init__(self, size):
        self.size = 1
        while self.size < size: self.size *= 2
        self.data = [0] * (self.size * 2 - 1)
    
    def update(self, i, x):
        i += (self.size - 1)
        self.data[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.data[i] = self.data[i*2+1] | self.data[i*2+2]
        
    def get(self, a, b, node=0, l=0, r=-1):
        if r < 0: r = self.size
        if r <= a or b <= l: return 0
        if a <= l and r <= b: return self.data[node]
        vl = self.get(a, b, node*2+1, l, (l+r)//2)
        vr = self.get(a, b, node*2+2, (l+r)//2, r)
        return vl | vr class SegT():
    def __init__(self, size):
        self.size = 1
        while self.size < size: self.size *= 2
        self.data = [0] * (self.size * 2 - 1)
    
    def update(self, i, x):
        i += (self.size - 1)
        self.data[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.data[i] = self.data[i*2+1] | self.data[i*2+2]
        
    def get(self, a, b, node=0, l=0, r=-1):
        if r < 0: r = self.size
        if r <= a or b <= l: return 0
        if a <= l and r <= b: return self.data[node]
        vl = self.get(a, b, node*2+1, l, (l+r)//2)
        vr = self.get(a, b, node*2+2, (l+r)//2, r)
        return vl | vr SegT x = ord(S[i]) - ord('a') ord(S[i]) - ord('a') x r = input().split() input().split() r
class SegT():
    def __init__(self, size):
        self.size = 1
        while self.size < size: self.size *= 2
        self.data = [0] * (self.size * 2 - 1)
    
    def update(self, i, x):
        i += (self.size - 1)
        self.data[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.data[i] = self.data[i*2+1] | self.data[i*2+2]
        
    def get(self, a, b, node=0, l=0, r=-1):
        if r < 0: r = self.size
        if r <= a or b <= l: return 0
        if a <= l and r <= b: return self.data[node]
        vl = self.get(a, b, node*2+1, l, (l+r)//2)
        vr = self.get(a, b, node*2+2, (l+r)//2, r)
        return vl | vr

N = int(input())
S = input()
Q = int(input())

segt = SegT(N)
for i in range(N):
    x = ord(S[i]) - ord('a')
    segt.update(i, (1<<x))

for i in range(Q):
    t, l, r = input().split()
    if t == "1":
        x = ord(r) - ord('a')
        segt.update(int(l)-1, (1<<x))
    else:
        x = segt.get(int(l)-1,int(r))
        ans = 0
        for i in range(26):
            if x>>i&1: ans += 1
        print(ans)
