class BIT:
    def __init__(self, n):
        """
            data : BIT木データ
            el : 元配列
        """
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    """A1 ~ Aiまでの累積和"""
    def Sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & (-i)   #LSB(Least Significant Bit)の獲得:i&(-i)
        return s
    
    """Ai += x"""
    def Add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    """Ai ~ Ajまでの累積和"""
    def Get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.Sum(j) - self.Sum(i)

def ctoi(c):
    return ord(c) - 97

n = int(input())
s = list(input())
q = int(input())

bits = [BIT(n) for _ in range(26)]
ans = []
for i in range(n):
    bits[ctoi(s[i])].Add(i+1, 1)
for _ in range(q):
    line = list(input().split())
    if line[0] == '1':
        idx = int(line[1])
        bits[ctoi(s[idx-1])].Add(idx, -1)
        s[idx-1] = line[2]
        bits[ctoi(line[2])].Add(idx, 1) 
    else:
        l,r = int(line[1]), int(line[2])
        cnt = 0
        for i in range(26):
            if bits[i].Get(l-1,r)!=0:
                cnt += 1
        ans.append(cnt)
for a in ans:
    print(a) class BIT:
    def __init__(self, n):
        """
            data : BIT木データ
            el : 元配列
        """
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    """A1 ~ Aiまでの累積和"""
    def Sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & (-i)   #LSB(Least Significant Bit)の獲得:i&(-i)
        return s
    
    """Ai += x"""
    def Add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    """Ai ~ Ajまでの累積和"""
    def Get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.Sum(j) - self.Sum(i) BIT def __init__(self, n):
        """
            data : BIT木データ
            el : 元配列
        """
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
     __init__ """
            data : BIT木データ
            el : 元配列
        """ self.n = n self.n self n n self.data = [0]*(n+1) self.data self data [0]*(n+1) [0] 0 n+1 n 1 self.el = [0]*(n+1) self.el self el [0]*(n+1) [0] 0 n+1 n 1 self self n n """A1 ~ Aiまでの累積和""" def Sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & (-i)   #LSB(Least Significant Bit)の獲得:i&(-i)
        return s
    
     Sum s = 0 s 0 while i > 0:
            s += self.data[i]
            i -= i & (-i)   #LSB(Least Significant Bit)の獲得:i&(-i)
         i > 0 i 0 s += self.data[i] s self.data[i] self.data self data i i -= i & (-i) i i & (-i) i -i i return s s self self i i """Ai += x""" def Add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
     Add self.el[i] += x self.el[i] self.el self el i x while i <= self.n:
            self.data[i] += x
            i += i & -i
    
     i <= self.n i self.n self n self.data[i] += x self.data[i] self.data self data i x i += i & -i i i & -i i -i i self self i i x x """Ai ~ Ajまでの累積和""" def Get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.Sum(j) - self.Sum(i) Get if j is None:
            return self.el[i]
         j is None j None return self.el[i] self.el[i] self.el self el i return self.Sum(j) - self.Sum(i) self.Sum(j) - self.Sum(i) self.Sum(j) self.Sum self Sum j self.Sum(i) self.Sum self Sum i self self i i j=None j None def ctoi(c):
    return ord(c) - 97 ctoi return ord(c) - 97 ord(c) - 97 ord(c) ord c 97 c c n = int(input()) n int(input()) int input() input s = list(input()) s list(input()) list input() input q = int(input()) q int(input()) int input() input BIT(n) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BIT(n) BIT n bits = [BIT(n) for _ in range(26)] bits [BIT(n) for _ in range(26)] ans = [] ans [] for i in range(n):
    bits[ctoi(s[i])].Add(i+1, 1) i range(n) range n bits[ctoi(s[i])].Add(i+1, 1) [ctoi(s[i])].Add [ctoi(s[i])] bits ctoi(s[i]) ctoi s[i] s i Add i+1 i 1 1 for _ in range(q):
    line = list(input().split())
    if line[0] == '1':
        idx = int(line[1])
        bits[ctoi(s[idx-1])].Add(idx, -1)
        s[idx-1] = line[2]
        bits[ctoi(line[2])].Add(idx, 1) 
    else:
        l,r = int(line[1]), int(line[2])
        cnt = 0
        for i in range(26):
            if bits[i].Get(l-1,r)!=0:
                cnt += 1
        ans.append(cnt) _ range(q) range q line = list(input().split()) line list(input().split()) list input().split() ().split () input split if line[0] == '1':
        idx = int(line[1])
        bits[ctoi(s[idx-1])].Add(idx, -1)
        s[idx-1] = line[2]
        bits[ctoi(line[2])].Add(idx, 1) 
    else:
        l,r = int(line[1]), int(line[2])
        cnt = 0
        for i in range(26):
            if bits[i].Get(l-1,r)!=0:
                cnt += 1
        ans.append(cnt) line[0] == '1' line[0] line 0 '1' idx = int(line[1]) idx int(line[1]) int line[1] line 1 bits[ctoi(s[idx-1])].Add(idx, -1) [ctoi(s[idx-1])].Add [ctoi(s[idx-1])] bits ctoi(s[idx-1]) ctoi s[idx-1] s idx-1 idx 1 Add idx -1 s[idx-1] = line[2] s[idx-1] s idx-1 idx 1 line[2] line 2 bits[ctoi(line[2])].Add(idx, 1) [ctoi(line[2])].Add [ctoi(line[2])] bits ctoi(line[2]) ctoi line[2] line 2 Add idx 1 l,r = int(line[1]), int(line[2]) l int(line[1]) int line[1] line 1 r int(line[2]) int line[2] line 2 cnt = 0 cnt 0 for i in range(26):
            if bits[i].Get(l-1,r)!=0:
                cnt += 1
         i range(26) range 26 if bits[i].Get(l-1,r)!=0:
                cnt += 1
         bits[i].Get(l-1,r)!=0 bits[i].Get(l-1,r) [i].Get [i] bits i Get l-1 l 1 r 0 cnt += 1 cnt 1 ans.append(cnt) ans.append ans append cnt for a in ans:
    print(a) a ans print(a) print a r = int(line[1]), int(line[2]) int(line[2]) r s = list(input()) list(input()) s n = int(input()) int(input()) n l,r = int(line[1]), int(line[2]) int(line[1]) l class BIT:
    def __init__(self, n):
        """
            data : BIT木データ
            el : 元配列
        """
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    """A1 ~ Aiまでの累積和"""
    def Sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & (-i)   #LSB(Least Significant Bit)の獲得:i&(-i)
        return s
    
    """Ai += x"""
    def Add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    """Ai ~ Ajまでの累積和"""
    def Get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.Sum(j) - self.Sum(i) class BIT:
    def __init__(self, n):
        """
            data : BIT木データ
            el : 元配列
        """
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    """A1 ~ Aiまでの累積和"""
    def Sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & (-i)   #LSB(Least Significant Bit)の獲得:i&(-i)
        return s
    
    """Ai += x"""
    def Add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    """Ai ~ Ajまでの累積和"""
    def Get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.Sum(j) - self.Sum(i) BIT ans = [] [] ans idx = int(line[1]) int(line[1]) idx q = int(input()) int(input()) q cnt = 0 0 cnt bits = [BIT(n) for _ in range(26)] [BIT(n) for _ in range(26)] bits line = list(input().split()) list(input().split()) line def ctoi(c):
    return ord(c) - 97 def ctoi(c):
    return ord(c) - 97 ctoi cnt += 1 1 cnt
class BIT:
    def __init__(self, n):
        """
            data : BIT木データ
            el : 元配列
        """
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    """A1 ~ Aiまでの累積和"""
    def Sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & (-i)   #LSB(Least Significant Bit)の獲得:i&(-i)
        return s
    
    """Ai += x"""
    def Add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    """Ai ~ Ajまでの累積和"""
    def Get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.Sum(j) - self.Sum(i)

def ctoi(c):
    return ord(c) - 97

n = int(input())
s = list(input())
q = int(input())

bits = [BIT(n) for _ in range(26)]
ans = []
for i in range(n):
    bits[ctoi(s[i])].Add(i+1, 1)
for _ in range(q):
    line = list(input().split())
    if line[0] == '1':
        idx = int(line[1])
        bits[ctoi(s[idx-1])].Add(idx, -1)
        s[idx-1] = line[2]
        bits[ctoi(line[2])].Add(idx, 1) 
    else:
        l,r = int(line[1]), int(line[2])
        cnt = 0
        for i in range(26):
            if bits[i].Get(l-1,r)!=0:
                cnt += 1
        ans.append(cnt)
for a in ans:
    print(a)