class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 0:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)


def solve():
    import sys
    from operator import add
    N = int(input())
    S = list(input())
    Q = int(input())
    Query = sys.stdin.readlines()

    a = ord('a')
    A = [[0] * N for _ in range(26)]
    for i, s in enumerate(S):
        s = ord(s) - a
        A[s][i] = 1
    seg = [SegmentTree(A[i], add, 0) for i in range(26)]

    for i in range(Q):
        t, x, y = Query[i].split()
        t = int(t)
        x = int(x) - 1
        if t == 1 and S[x] != y:
            c = S[x]
            S[x] = y
            seg[ord(c) - a].update(x, 0)
            seg[ord(y) - a].update(x, 1)
            continue
        elif t == 2:
            y = int(y) - 1
            ans = 0
            for j in range(26):
                ans += (seg[j].get(x, y + 1)) > 0
            print(ans)


solve() class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 0:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr) SegmentTree """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """ def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
     __init__ """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """ n = 2 ** (len(A) - 1).bit_length() n 2 ** (len(A) - 1).bit_length() 2 (len(A) - 1).bit_length() len(A) - 1).bit_length len(A) - 1 len(A) len A 1 bit_length self.__n = n self.__n self __n n self.__dot = dot self.__dot self __dot dot self.__e = e self.__e self __e e self.__node = [e] * (2 * n) self.__node self __node [e] * (2 * n) [e] e 2 * n 2 n for i in range(len(A)):
            self.__node[i + n] = A[i]
         i range(len(A)) range len(A) len A self.__node[i + n] = A[i] self.__node[i + n] self.__node self __node i + n i n A[i] A i for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
     i range(n - 1, 0, -1) range n - 1 n 1 0 -1 self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1]) self.__node[i] self.__node self __node i self.__dot(self.__node[2 * i], self.__node[2 * i + 1]) self.__dot self __dot self.__node[2 * i] self.__node self __node 2 * i 2 i self.__node[2 * i + 1] self.__node self __node 2 * i + 1 2 * i 2 i 1 self self A A dot dot e e def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 0:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

     update i += self.__n i self.__n self __n node = self.__node node self.__node self __node node[i] = c node[i] node i c while i > 0:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

     i > 0 i 0 i //= 2 i 2 node[i] = self.__dot(node[2 * i], node[2 * i + 1]) node[i] node i self.__dot(node[2 * i], node[2 * i + 1]) self.__dot self __dot node[2 * i] node 2 * i 2 i node[2 * i + 1] node 2 * i + 1 2 * i 2 i 1 self self i i c c def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr) get vl, vr = self.__e, self.__e vl self.__e self __e vr self.__e self __e l += self.__n l self.__n self __n r += self.__n r self.__n self __n while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
         l < r l r if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
             l & 1 l 1 vl = self.__dot(vl, self.__node[l]) vl self.__dot(vl, self.__node[l]) self.__dot self __dot vl self.__node[l] self.__node self __node l l += 1 l 1 l //= 2 l 2 if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
             r & 1 r 1 r -= 1 r 1 vr = self.__dot(vr, self.__node[r]) vr self.__dot(vr, self.__node[r]) self.__dot self __dot vr self.__node[r] self.__node self __node r r //= 2 r 2 return self.__dot(vl, vr) self.__dot(vl, vr) self.__dot self __dot vl vr self self l l r r def solve():
    import sys
    from operator import add
    N = int(input())
    S = list(input())
    Q = int(input())
    Query = sys.stdin.readlines()

    a = ord('a')
    A = [[0] * N for _ in range(26)]
    for i, s in enumerate(S):
        s = ord(s) - a
        A[s][i] = 1
    seg = [SegmentTree(A[i], add, 0) for i in range(26)]

    for i in range(Q):
        t, x, y = Query[i].split()
        t = int(t)
        x = int(x) - 1
        if t == 1 and S[x] != y:
            c = S[x]
            S[x] = y
            seg[ord(c) - a].update(x, 0)
            seg[ord(y) - a].update(x, 1)
            continue
        elif t == 2:
            y = int(y) - 1
            ans = 0
            for j in range(26):
                ans += (seg[j].get(x, y + 1)) > 0
            print(ans) solve import sys sys from operator import add 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 Query = sys.stdin.readlines() Query sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines a = ord('a') a ord('a') ord 'a' [0] * N for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [0] * N [0] 0 N A = [[0] * N for _ in range(26)] A [[0] * N for _ in range(26)] for i, s in enumerate(S):
        s = ord(s) - a
        A[s][i] = 1
     i s enumerate(S) enumerate S s = ord(s) - a s ord(s) - a ord(s) ord s a A[s][i] = 1 A[s][i] [s] A s i 1 SegmentTree(A[i], add, 0) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) SegmentTree(A[i], add, 0) SegmentTree A[i] A i add 0 seg = [SegmentTree(A[i], add, 0) for i in range(26)] seg [SegmentTree(A[i], add, 0) for i in range(26)] for i in range(Q):
        t, x, y = Query[i].split()
        t = int(t)
        x = int(x) - 1
        if t == 1 and S[x] != y:
            c = S[x]
            S[x] = y
            seg[ord(c) - a].update(x, 0)
            seg[ord(y) - a].update(x, 1)
            continue
        elif t == 2:
            y = int(y) - 1
            ans = 0
            for j in range(26):
                ans += (seg[j].get(x, y + 1)) > 0
            print(ans) i range(Q) range Q t, x, y = Query[i].split() t Query[i].split() [i].split [i] Query i split x y t = int(t) t int(t) int t x = int(x) - 1 x int(x) - 1 int(x) int x 1 if t == 1 and S[x] != y:
            c = S[x]
            S[x] = y
            seg[ord(c) - a].update(x, 0)
            seg[ord(y) - a].update(x, 1)
            continue
        elif t == 2:
            y = int(y) - 1
            ans = 0
            for j in range(26):
                ans += (seg[j].get(x, y + 1)) > 0
            print(ans) t == 1 and S[x] != y t == 1 t 1 S[x] != y S[x] S x y c = S[x] c S[x] S x S[x] = y S[x] S x y seg[ord(c) - a].update(x, 0) [ord(c) - a].update [ord(c) - a] seg ord(c) - a ord(c) ord c a update x 0 seg[ord(y) - a].update(x, 1) [ord(y) - a].update [ord(y) - a] seg ord(y) - a ord(y) ord y a update x 1 continue elif t == 2:
            y = int(y) - 1
            ans = 0
            for j in range(26):
                ans += (seg[j].get(x, y + 1)) > 0
            print(ans) t == 2 t 2 y = int(y) - 1 y int(y) - 1 int(y) int y 1 ans = 0 ans 0 for j in range(26):
                ans += (seg[j].get(x, y + 1)) > 0
             j range(26) range 26 ans += (seg[j].get(x, y + 1)) > 0 ans (seg[j].get(x, y + 1)) > 0 seg[j].get(x, y + 1) [j].get [j] seg j get x y + 1 y 1 0 print(ans) print ans solve() solve class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 0:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr) class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 0:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr) SegmentTree def solve():
    import sys
    from operator import add
    N = int(input())
    S = list(input())
    Q = int(input())
    Query = sys.stdin.readlines()

    a = ord('a')
    A = [[0] * N for _ in range(26)]
    for i, s in enumerate(S):
        s = ord(s) - a
        A[s][i] = 1
    seg = [SegmentTree(A[i], add, 0) for i in range(26)]

    for i in range(Q):
        t, x, y = Query[i].split()
        t = int(t)
        x = int(x) - 1
        if t == 1 and S[x] != y:
            c = S[x]
            S[x] = y
            seg[ord(c) - a].update(x, 0)
            seg[ord(y) - a].update(x, 1)
            continue
        elif t == 2:
            y = int(y) - 1
            ans = 0
            for j in range(26):
                ans += (seg[j].get(x, y + 1)) > 0
            print(ans) def solve():
    import sys
    from operator import add
    N = int(input())
    S = list(input())
    Q = int(input())
    Query = sys.stdin.readlines()

    a = ord('a')
    A = [[0] * N for _ in range(26)]
    for i, s in enumerate(S):
        s = ord(s) - a
        A[s][i] = 1
    seg = [SegmentTree(A[i], add, 0) for i in range(26)]

    for i in range(Q):
        t, x, y = Query[i].split()
        t = int(t)
        x = int(x) - 1
        if t == 1 and S[x] != y:
            c = S[x]
            S[x] = y
            seg[ord(c) - a].update(x, 0)
            seg[ord(y) - a].update(x, 1)
            continue
        elif t == 2:
            y = int(y) - 1
            ans = 0
            for j in range(26):
                ans += (seg[j].get(x, y + 1)) > 0
            print(ans) solve
class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 0:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)


def solve():
    import sys
    from operator import add
    N = int(input())
    S = list(input())
    Q = int(input())
    Query = sys.stdin.readlines()

    a = ord('a')
    A = [[0] * N for _ in range(26)]
    for i, s in enumerate(S):
        s = ord(s) - a
        A[s][i] = 1
    seg = [SegmentTree(A[i], add, 0) for i in range(26)]

    for i in range(Q):
        t, x, y = Query[i].split()
        t = int(t)
        x = int(x) - 1
        if t == 1 and S[x] != y:
            c = S[x]
            S[x] = y
            seg[ord(c) - a].update(x, 0)
            seg[ord(y) - a].update(x, 1)
            continue
        elif t == 2:
            y = int(y) - 1
            ans = 0
            for j in range(26):
                ans += (seg[j].get(x, y + 1)) > 0
            print(ans)


solve()
