
class BIT:
    """Binary Indexed Tree (Fenwick Tree)
    Range Sum QueryにO(log N)時間で答える
    1-indexed
    """
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()
 
    def sum(self, i):
        """a[1]~a[i]の区間和を取得"""
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        """a[i]にxを足す"""
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_
 
def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    alphabets = list("abcdefghijklmnopqrstuvwxyz")
    c2n = {c: i for i, c in enumerate(alphabets)}
    
    Trees = [BIT(N+2) for _ in range(26)]

    for i in range(N):
        Trees[c2n[S[i]]].add(i+1, 1)
    
    for _ in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            _, i, c = tmp
            i = int(i)
            Trees[c2n[S[i-1]]].add(i, -1)
            Trees[c2n[c]].add(i, 1)
            S[i-1] = c
        else:
            ans = 0
            _, l, r = tmp
            l = int(l)
            r = int(r)
            for char in range(26):
                if Trees[char].sum(r) - Trees[char].sum(l-1) > 0:
                    ans += 1
            print(ans)

if __name__ == "__main__":
    main() class BIT:
    """Binary Indexed Tree (Fenwick Tree)
    Range Sum QueryにO(log N)時間で答える
    1-indexed
    """
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()
 
    def sum(self, i):
        """a[1]~a[i]の区間和を取得"""
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        """a[i]にxを足す"""
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_
  BIT """Binary Indexed Tree (Fenwick Tree)
    Range Sum QueryにO(log N)時間で答える
    1-indexed
    """ def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()
 
     __init__ self.size = n self.size self size n self.tree = [0] * (n + 1) self.tree self tree [0] * (n + 1) [0] 0 n + 1 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 sum(self, i):
        """a[1]~a[i]の区間和を取得"""
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
     sum """a[1]~a[i]の区間和を取得""" s = 0 s 0 while i > 0:
            s += self.tree[i]
            i -= i & -i
         i > 0 i 0 s += self.tree[i] s self.tree[i] self.tree self tree i i -= i & -i i i & -i i -i i return s s self self i i def add(self, i, x):
        """a[i]にxを足す"""
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

     add """a[i]にxを足す""" while i <= self.size:
            self.tree[i] += x
            i += i & -i

     i <= self.size i self.size self size self.tree[i] += x self.tree[i] self.tree self tree i x i += i & -i i i & -i i -i i self self i i x x def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_
  lower_bound """ 累積和がx以上になる最小のindexと、その直前までの累積和 """ sum_ = 0 sum_ 0 pos = 0 pos 0 for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
         i range(self.depth, -1, -1) range self.depth self depth -1 -1 k = pos + (1 << i) k pos + (1 << i) pos 1 << i 1 i if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
         k <= self.size and sum_ + self.tree[k] < x k <= self.size k self.size self size sum_ + self.tree[k] < x sum_ + self.tree[k] sum_ self.tree[k] self.tree self tree k x sum_ += self.tree[k] sum_ self.tree[k] self.tree self tree k pos += 1 << i pos 1 << i 1 i return pos + 1, sum_ return pos + 1, sum_ pos + 1 pos 1 sum_ self self x x def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    alphabets = list("abcdefghijklmnopqrstuvwxyz")
    c2n = {c: i for i, c in enumerate(alphabets)}
    
    Trees = [BIT(N+2) for _ in range(26)]

    for i in range(N):
        Trees[c2n[S[i]]].add(i+1, 1)
    
    for _ in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            _, i, c = tmp
            i = int(i)
            Trees[c2n[S[i-1]]].add(i, -1)
            Trees[c2n[c]].add(i, 1)
            S[i-1] = c
        else:
            ans = 0
            _, l, r = tmp
            l = int(l)
            r = int(r)
            for char in range(26):
                if Trees[char].sum(r) - Trees[char].sum(l-1) > 0:
                    ans += 1
            print(ans) main 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 alphabets = list("abcdefghijklmnopqrstuvwxyz") alphabets list("abcdefghijklmnopqrstuvwxyz") list "abcdefghijklmnopqrstuvwxyz" c: i for i, c in enumerate(alphabets) for i, c in enumerate(alphabets) i c enumerate(alphabets) enumerate alphabets for i, c in enumerate(alphabets) c i c2n = {c: i for i, c in enumerate(alphabets)} c2n {c: i for i, c in enumerate(alphabets)} BIT(N+2) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BIT(N+2) BIT N+2 N 2 Trees = [BIT(N+2) for _ in range(26)] Trees [BIT(N+2) for _ in range(26)] for i in range(N):
        Trees[c2n[S[i]]].add(i+1, 1)
    
     i range(N) range N Trees[c2n[S[i]]].add(i+1, 1) [c2n[S[i]]].add [c2n[S[i]]] Trees c2n[S[i]] c2n S[i] S i add i+1 i 1 1 for _ in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            _, i, c = tmp
            i = int(i)
            Trees[c2n[S[i-1]]].add(i, -1)
            Trees[c2n[c]].add(i, 1)
            S[i-1] = c
        else:
            ans = 0
            _, l, r = tmp
            l = int(l)
            r = int(r)
            for char in range(26):
                if Trees[char].sum(r) - Trees[char].sum(l-1) > 0:
                    ans += 1
            print(ans) _ range(Q) range Q tmp = list(input().split()) tmp list(input().split()) list input().split() ().split () input split if tmp[0] == "1":
            _, i, c = tmp
            i = int(i)
            Trees[c2n[S[i-1]]].add(i, -1)
            Trees[c2n[c]].add(i, 1)
            S[i-1] = c
        else:
            ans = 0
            _, l, r = tmp
            l = int(l)
            r = int(r)
            for char in range(26):
                if Trees[char].sum(r) - Trees[char].sum(l-1) > 0:
                    ans += 1
            print(ans) tmp[0] == "1" tmp[0] tmp 0 "1" _, i, c = tmp _ tmp i c i = int(i) i int(i) int i Trees[c2n[S[i-1]]].add(i, -1) [c2n[S[i-1]]].add [c2n[S[i-1]]] Trees c2n[S[i-1]] c2n S[i-1] S i-1 i 1 add i -1 Trees[c2n[c]].add(i, 1) [c2n[c]].add [c2n[c]] Trees c2n[c] c2n c add i 1 S[i-1] = c S[i-1] S i-1 i 1 c ans = 0 ans 0 _, l, r = tmp _ tmp l r l = int(l) l int(l) int l r = int(r) r int(r) int r for char in range(26):
                if Trees[char].sum(r) - Trees[char].sum(l-1) > 0:
                    ans += 1
             char range(26) range 26 if Trees[char].sum(r) - Trees[char].sum(l-1) > 0:
                    ans += 1
             Trees[char].sum(r) - Trees[char].sum(l-1) > 0 Trees[char].sum(r) - Trees[char].sum(l-1) Trees[char].sum(r) [char].sum [char] Trees char sum r Trees[char].sum(l-1) [char].sum [char] Trees char sum l-1 l 1 0 ans += 1 ans 1 print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main class BIT:
    """Binary Indexed Tree (Fenwick Tree)
    Range Sum QueryにO(log N)時間で答える
    1-indexed
    """
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()
 
    def sum(self, i):
        """a[1]~a[i]の区間和を取得"""
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        """a[i]にxを足す"""
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_
  class BIT:
    """Binary Indexed Tree (Fenwick Tree)
    Range Sum QueryにO(log N)時間で答える
    1-indexed
    """
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()
 
    def sum(self, i):
        """a[1]~a[i]の区間和を取得"""
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        """a[i]にxを足す"""
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_
  BIT def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    alphabets = list("abcdefghijklmnopqrstuvwxyz")
    c2n = {c: i for i, c in enumerate(alphabets)}
    
    Trees = [BIT(N+2) for _ in range(26)]

    for i in range(N):
        Trees[c2n[S[i]]].add(i+1, 1)
    
    for _ in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            _, i, c = tmp
            i = int(i)
            Trees[c2n[S[i-1]]].add(i, -1)
            Trees[c2n[c]].add(i, 1)
            S[i-1] = c
        else:
            ans = 0
            _, l, r = tmp
            l = int(l)
            r = int(r)
            for char in range(26):
                if Trees[char].sum(r) - Trees[char].sum(l-1) > 0:
                    ans += 1
            print(ans) def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    alphabets = list("abcdefghijklmnopqrstuvwxyz")
    c2n = {c: i for i, c in enumerate(alphabets)}
    
    Trees = [BIT(N+2) for _ in range(26)]

    for i in range(N):
        Trees[c2n[S[i]]].add(i+1, 1)
    
    for _ in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            _, i, c = tmp
            i = int(i)
            Trees[c2n[S[i-1]]].add(i, -1)
            Trees[c2n[c]].add(i, 1)
            S[i-1] = c
        else:
            ans = 0
            _, l, r = tmp
            l = int(l)
            r = int(r)
            for char in range(26):
                if Trees[char].sum(r) - Trees[char].sum(l-1) > 0:
                    ans += 1
            print(ans) main

class BIT:
    """Binary Indexed Tree (Fenwick Tree)
    Range Sum QueryにO(log N)時間で答える
    1-indexed
    """
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()
 
    def sum(self, i):
        """a[1]~a[i]の区間和を取得"""
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        """a[i]にxを足す"""
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_
 
def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    alphabets = list("abcdefghijklmnopqrstuvwxyz")
    c2n = {c: i for i, c in enumerate(alphabets)}
    
    Trees = [BIT(N+2) for _ in range(26)]

    for i in range(N):
        Trees[c2n[S[i]]].add(i+1, 1)
    
    for _ in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            _, i, c = tmp
            i = int(i)
            Trees[c2n[S[i-1]]].add(i, -1)
            Trees[c2n[c]].add(i, 1)
            S[i-1] = c
        else:
            ans = 0
            _, l, r = tmp
            l = int(l)
            r = int(r)
            for char in range(26):
                if Trees[char].sum(r) - Trees[char].sum(l-1) > 0:
                    ans += 1
            print(ans)

if __name__ == "__main__":
    main()