# https://atcoder.jp/contests/abc157/tasks/abc157_e

import sys
input = sys.stdin.readline


class SegmentTree:

    def __init__(self, n, op, e):
        """
        :param n: 要素数
        :param op: 二項演算
        :param e: 単位減
        例) 区間最小値  SegmentTree(n, lambda a, b : a if a < b else b, 10 ** 18)
            区間和     SegmentTree(n, lambda a, b : a + b, 0)
        """
        self.n = n
        self.op = op
        self.e = e
        self.size = 1 << (self.n - 1).bit_length()      # st[self.size + i] = array[i]
        self.tree = [self.e] * (self.size << 1)

    def built(self, array):
        """arrayを初期値とするセグメント木を構築"""
        for i in range(self.n):
            self.tree[self.size + i] = array[i]
        for i in range(self.size - 1, 0, -1):
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

    def update(self, i, x):
        """i 番目の要素を x に更新"""
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

    def get_val(self, l, r):
        """[l, r)の畳み込みの結果を返す"""
        l, r = l + self.size, r + self.size
        res = self.e
        while l < r:
            if l & 1:
                res = self.op(self.tree[l], res)
                l += 1
            if r & 1:
                r -= 1
                res = self.op(self.tree[r], res)
            l, r = l >> 1, r >> 1
        return res


##################################################################################################################

def popcount(x):
    return bin(x).count("1")

N = int(input())
st = SegmentTree(N, lambda a, b: a | b, 0)
S = input().strip()
data = []
for s in S:
    data.append(1 << (ord(s) - ord("a")))
st.built(data)
Q = int(input())
for _ in range(Q):
    q, a, b = input().split()
    if q == "1":
        st.update(int(a)-1, 1 << (ord(b) - ord("a")))
    if q == "2":
        a = int(a) - 1
        b = int(b)
        print(popcount(st.get_val(a, b))) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline class SegmentTree:

    def __init__(self, n, op, e):
        """
        :param n: 要素数
        :param op: 二項演算
        :param e: 単位減
        例) 区間最小値  SegmentTree(n, lambda a, b : a if a < b else b, 10 ** 18)
            区間和     SegmentTree(n, lambda a, b : a + b, 0)
        """
        self.n = n
        self.op = op
        self.e = e
        self.size = 1 << (self.n - 1).bit_length()      # st[self.size + i] = array[i]
        self.tree = [self.e] * (self.size << 1)

    def built(self, array):
        """arrayを初期値とするセグメント木を構築"""
        for i in range(self.n):
            self.tree[self.size + i] = array[i]
        for i in range(self.size - 1, 0, -1):
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

    def update(self, i, x):
        """i 番目の要素を x に更新"""
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

    def get_val(self, l, r):
        """[l, r)の畳み込みの結果を返す"""
        l, r = l + self.size, r + self.size
        res = self.e
        while l < r:
            if l & 1:
                res = self.op(self.tree[l], res)
                l += 1
            if r & 1:
                r -= 1
                res = self.op(self.tree[r], res)
            l, r = l >> 1, r >> 1
        return res


################################################################################################################## SegmentTree def __init__(self, n, op, e):
        """
        :param n: 要素数
        :param op: 二項演算
        :param e: 単位減
        例) 区間最小値  SegmentTree(n, lambda a, b : a if a < b else b, 10 ** 18)
            区間和     SegmentTree(n, lambda a, b : a + b, 0)
        """
        self.n = n
        self.op = op
        self.e = e
        self.size = 1 << (self.n - 1).bit_length()      # st[self.size + i] = array[i]
        self.tree = [self.e] * (self.size << 1)

     __init__ """
        :param n: 要素数
        :param op: 二項演算
        :param e: 単位減
        例) 区間最小値  SegmentTree(n, lambda a, b : a if a < b else b, 10 ** 18)
            区間和     SegmentTree(n, lambda a, b : a + b, 0)
        """ self.n = n self.n self n n self.op = op self.op self op op self.e = e self.e self e e self.size = 1 << (self.n - 1).bit_length() self.size self size 1 << (self.n - 1).bit_length() 1 (self.n - 1).bit_length() self.n - 1).bit_length self.n - 1 self.n self n 1 bit_length self.tree = [self.e] * (self.size << 1) self.tree self tree [self.e] * (self.size << 1) [self.e] self.e self e self.size << 1 self.size self size 1 self self n n op op e e def built(self, array):
        """arrayを初期値とするセグメント木を構築"""
        for i in range(self.n):
            self.tree[self.size + i] = array[i]
        for i in range(self.size - 1, 0, -1):
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

     built """arrayを初期値とするセグメント木を構築""" for i in range(self.n):
            self.tree[self.size + i] = array[i]
         i range(self.n) range self.n self n self.tree[self.size + i] = array[i] self.tree[self.size + i] self.tree self tree self.size + i self.size self size i array[i] array i for i in range(self.size - 1, 0, -1):
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

     i range(self.size - 1, 0, -1) range self.size - 1 self.size self size 1 0 -1 self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1]) self.tree[i] self.tree self tree i self.op(self.tree[i << 1], self.tree[(i << 1) + 1]) self.op self op self.tree[i << 1] self.tree self tree i << 1 i 1 self.tree[(i << 1) + 1] self.tree self tree (i << 1) + 1 i << 1 i 1 1 self self array array def update(self, i, x):
        """i 番目の要素を x に更新"""
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

     update """i 番目の要素を x に更新""" i += self.size i self.size self size self.tree[i] = x self.tree[i] self.tree self tree i x while i > 1:
            i >>= 1
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

     i > 1 i 1 i >>= 1 i 1 self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1]) self.tree[i] self.tree self tree i self.op(self.tree[i << 1], self.tree[(i << 1) + 1]) self.op self op self.tree[i << 1] self.tree self tree i << 1 i 1 self.tree[(i << 1) + 1] self.tree self tree (i << 1) + 1 i << 1 i 1 1 self self i i x x def get_val(self, l, r):
        """[l, r)の畳み込みの結果を返す"""
        l, r = l + self.size, r + self.size
        res = self.e
        while l < r:
            if l & 1:
                res = self.op(self.tree[l], res)
                l += 1
            if r & 1:
                r -= 1
                res = self.op(self.tree[r], res)
            l, r = l >> 1, r >> 1
        return res


################################################################################################################## get_val """[l, r)の畳み込みの結果を返す""" l, r = l + self.size, r + self.size l l + self.size l self.size self size r r + self.size r self.size self size res = self.e res self.e self e while l < r:
            if l & 1:
                res = self.op(self.tree[l], res)
                l += 1
            if r & 1:
                r -= 1
                res = self.op(self.tree[r], res)
            l, r = l >> 1, r >> 1
         l < r l r if l & 1:
                res = self.op(self.tree[l], res)
                l += 1
             l & 1 l 1 res = self.op(self.tree[l], res) res self.op(self.tree[l], res) self.op self op self.tree[l] self.tree self tree l res l += 1 l 1 if r & 1:
                r -= 1
                res = self.op(self.tree[r], res)
             r & 1 r 1 r -= 1 r 1 res = self.op(self.tree[r], res) res self.op(self.tree[r], res) self.op self op self.tree[r] self.tree self tree r res l, r = l >> 1, r >> 1 l l >> 1 l 1 r r >> 1 r 1 return res res self self l l r r def popcount(x):
    return bin(x).count("1") popcount return bin(x).count("1") bin(x).count("1") (x).count (x) bin x count "1" x x N = int(input()) N int(input()) int input() input st = SegmentTree(N, lambda a, b: a | b, 0) st SegmentTree(N, lambda a, b: a | b, 0) SegmentTree N lambda a, b: a | b a | b a b a b 0 S = input().strip() S input().strip() ().strip () input strip data = [] data [] for s in S:
    data.append(1 << (ord(s) - ord("a"))) s S data.append(1 << (ord(s) - ord("a"))) data.append data append 1 << (ord(s) - ord("a")) 1 ord(s) - ord("a") ord(s) ord s ord("a") ord "a" st.built(data) st.built st built data Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    q, a, b = input().split()
    if q == "1":
        st.update(int(a)-1, 1 << (ord(b) - ord("a")))
    if q == "2":
        a = int(a) - 1
        b = int(b)
        print(popcount(st.get_val(a, b))) _ range(Q) range Q q, a, b = input().split() q input().split() ().split () input split a b if q == "1":
        st.update(int(a)-1, 1 << (ord(b) - ord("a")))
     q == "1" q "1" st.update(int(a)-1, 1 << (ord(b) - ord("a"))) st.update st update int(a)-1 int(a) int a 1 1 << (ord(b) - ord("a")) 1 ord(b) - ord("a") ord(b) ord b ord("a") ord "a" if q == "2":
        a = int(a) - 1
        b = int(b)
        print(popcount(st.get_val(a, b))) q == "2" q "2" a = int(a) - 1 a int(a) - 1 int(a) int a 1 b = int(b) b int(b) int b print(popcount(st.get_val(a, b))) print popcount(st.get_val(a, b)) popcount st.get_val(a, b) st.get_val st get_val a b st = SegmentTree(N, lambda a, b: a | b, 0) SegmentTree(N, lambda a, b: a | b, 0) st def popcount(x):
    return bin(x).count("1") def popcount(x):
    return bin(x).count("1") popcount data = [] [] data b = int(b) int(b) b b = input().split() input().split() b class SegmentTree:

    def __init__(self, n, op, e):
        """
        :param n: 要素数
        :param op: 二項演算
        :param e: 単位減
        例) 区間最小値  SegmentTree(n, lambda a, b : a if a < b else b, 10 ** 18)
            区間和     SegmentTree(n, lambda a, b : a + b, 0)
        """
        self.n = n
        self.op = op
        self.e = e
        self.size = 1 << (self.n - 1).bit_length()      # st[self.size + i] = array[i]
        self.tree = [self.e] * (self.size << 1)

    def built(self, array):
        """arrayを初期値とするセグメント木を構築"""
        for i in range(self.n):
            self.tree[self.size + i] = array[i]
        for i in range(self.size - 1, 0, -1):
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

    def update(self, i, x):
        """i 番目の要素を x に更新"""
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

    def get_val(self, l, r):
        """[l, r)の畳み込みの結果を返す"""
        l, r = l + self.size, r + self.size
        res = self.e
        while l < r:
            if l & 1:
                res = self.op(self.tree[l], res)
                l += 1
            if r & 1:
                r -= 1
                res = self.op(self.tree[r], res)
            l, r = l >> 1, r >> 1
        return res


################################################################################################################## class SegmentTree:

    def __init__(self, n, op, e):
        """
        :param n: 要素数
        :param op: 二項演算
        :param e: 単位減
        例) 区間最小値  SegmentTree(n, lambda a, b : a if a < b else b, 10 ** 18)
            区間和     SegmentTree(n, lambda a, b : a + b, 0)
        """
        self.n = n
        self.op = op
        self.e = e
        self.size = 1 << (self.n - 1).bit_length()      # st[self.size + i] = array[i]
        self.tree = [self.e] * (self.size << 1)

    def built(self, array):
        """arrayを初期値とするセグメント木を構築"""
        for i in range(self.n):
            self.tree[self.size + i] = array[i]
        for i in range(self.size - 1, 0, -1):
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

    def update(self, i, x):
        """i 番目の要素を x に更新"""
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

    def get_val(self, l, r):
        """[l, r)の畳み込みの結果を返す"""
        l, r = l + self.size, r + self.size
        res = self.e
        while l < r:
            if l & 1:
                res = self.op(self.tree[l], res)
                l += 1
            if r & 1:
                r -= 1
                res = self.op(self.tree[r], res)
            l, r = l >> 1, r >> 1
        return res


################################################################################################################## SegmentTree N = int(input()) int(input()) N Q = int(input()) int(input()) Q a = int(a) - 1 int(a) - 1 a a, b = input().split() input().split() a input = sys.stdin.readline sys.stdin.readline input q, a, b = input().split() input().split() q S = input().strip() input().strip() S
# https://atcoder.jp/contests/abc157/tasks/abc157_e

import sys
input = sys.stdin.readline


class SegmentTree:

    def __init__(self, n, op, e):
        """
        :param n: 要素数
        :param op: 二項演算
        :param e: 単位減
        例) 区間最小値  SegmentTree(n, lambda a, b : a if a < b else b, 10 ** 18)
            区間和     SegmentTree(n, lambda a, b : a + b, 0)
        """
        self.n = n
        self.op = op
        self.e = e
        self.size = 1 << (self.n - 1).bit_length()      # st[self.size + i] = array[i]
        self.tree = [self.e] * (self.size << 1)

    def built(self, array):
        """arrayを初期値とするセグメント木を構築"""
        for i in range(self.n):
            self.tree[self.size + i] = array[i]
        for i in range(self.size - 1, 0, -1):
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

    def update(self, i, x):
        """i 番目の要素を x に更新"""
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.op(self.tree[i << 1], self.tree[(i << 1) + 1])

    def get_val(self, l, r):
        """[l, r)の畳み込みの結果を返す"""
        l, r = l + self.size, r + self.size
        res = self.e
        while l < r:
            if l & 1:
                res = self.op(self.tree[l], res)
                l += 1
            if r & 1:
                r -= 1
                res = self.op(self.tree[r], res)
            l, r = l >> 1, r >> 1
        return res


##################################################################################################################

def popcount(x):
    return bin(x).count("1")

N = int(input())
st = SegmentTree(N, lambda a, b: a | b, 0)
S = input().strip()
data = []
for s in S:
    data.append(1 << (ord(s) - ord("a")))
st.built(data)
Q = int(input())
for _ in range(Q):
    q, a, b = input().split()
    if q == "1":
        st.update(int(a)-1, 1 << (ord(b) - ord("a")))
    if q == "2":
        a = int(a) - 1
        b = int(b)
        print(popcount(st.get_val(a, b)))