SIZE = 2**20 # 2**20 > N=500000

class SegmentTree:
    def __init__(self, size):
        self.size = size
        self.seg = [0] * (2 * size)

    def update(self, pos, ch):
        # update leaf
        i = self.size + pos - 1
        self.seg[i] = 1 << (ord(ch)-ord('a'))
        # update tree
        while i > 0:
            i = (i - 1) // 2
            self.seg[i] = self.seg[i*2+1] | self.seg[i*2+2]

    def _query(self, a, b, k, left, right):
        if right<a or b<left:
            return 0
        if a<=left and right<=b:
            return self.seg[k]

        vl = self._query(a,b,k*2+1, left, (left+right)//2)
        vr = self._query(a,b,k*2+2, (left+right)//2+1, right)
        return vl | vr

    def query(self, a, b):
        return self._query(a,b,0,0,self.size-1)


def resolve():
    N = int(input())
    S = input().strip()
    Q = int(input())
    table = [[] for _ in range(26)]
    sg = SegmentTree(SIZE)
    for i,ch in enumerate(S):
        sg.update(i, ch)

    for i in range(Q):
        query = input().strip().split()
        if query[0] == '1':
            pos = int(query[1])-1
            sg.update(pos, query[2])
        else:
            left = int(query[1])-1
            right = int(query[2])-1
            bits = sg.query(left, right)
            count = 0
            for j in range(26):
                count += (bits>>j) & 1
            print(count)

resolve() SIZE = 2**20 SIZE 2**20 2 20 class SegmentTree:
    def __init__(self, size):
        self.size = size
        self.seg = [0] * (2 * size)

    def update(self, pos, ch):
        # update leaf
        i = self.size + pos - 1
        self.seg[i] = 1 << (ord(ch)-ord('a'))
        # update tree
        while i > 0:
            i = (i - 1) // 2
            self.seg[i] = self.seg[i*2+1] | self.seg[i*2+2]

    def _query(self, a, b, k, left, right):
        if right<a or b<left:
            return 0
        if a<=left and right<=b:
            return self.seg[k]

        vl = self._query(a,b,k*2+1, left, (left+right)//2)
        vr = self._query(a,b,k*2+2, (left+right)//2+1, right)
        return vl | vr

    def query(self, a, b):
        return self._query(a,b,0,0,self.size-1) SegmentTree def __init__(self, size):
        self.size = size
        self.seg = [0] * (2 * size)

     __init__ self.size = size self.size self size size self.seg = [0] * (2 * size) self.seg self seg [0] * (2 * size) [0] 0 2 * size 2 size self self size size def update(self, pos, ch):
        # update leaf
        i = self.size + pos - 1
        self.seg[i] = 1 << (ord(ch)-ord('a'))
        # update tree
        while i > 0:
            i = (i - 1) // 2
            self.seg[i] = self.seg[i*2+1] | self.seg[i*2+2]

     update i = self.size + pos - 1 i self.size + pos - 1 self.size + pos self.size self size pos 1 self.seg[i] = 1 << (ord(ch)-ord('a')) self.seg[i] self.seg self seg i 1 << (ord(ch)-ord('a')) 1 ord(ch)-ord('a') ord(ch) ord ch ord('a') ord 'a' while i > 0:
            i = (i - 1) // 2
            self.seg[i] = self.seg[i*2+1] | self.seg[i*2+2]

     i > 0 i 0 i = (i - 1) // 2 i (i - 1) // 2 i - 1 i 1 2 self.seg[i] = self.seg[i*2+1] | self.seg[i*2+2] self.seg[i] self.seg self seg i self.seg[i*2+1] | self.seg[i*2+2] self.seg[i*2+1] self.seg self seg i*2+1 i*2 i 2 1 self.seg[i*2+2] self.seg self seg i*2+2 i*2 i 2 2 self self pos pos ch ch def _query(self, a, b, k, left, right):
        if right<a or b<left:
            return 0
        if a<=left and right<=b:
            return self.seg[k]

        vl = self._query(a,b,k*2+1, left, (left+right)//2)
        vr = self._query(a,b,k*2+2, (left+right)//2+1, right)
        return vl | vr

     _query if right<a or b<left:
            return 0
         right<a or b<left right<a right a b<left b left return 0 0 if a<=left and right<=b:
            return self.seg[k]

         a<=left and right<=b a<=left a left right<=b right b return self.seg[k] self.seg[k] self.seg self seg k vl = self._query(a,b,k*2+1, left, (left+right)//2) vl self._query(a,b,k*2+1, left, (left+right)//2) self._query self _query a b k*2+1 k*2 k 2 1 left (left+right)//2 left+right left right 2 vr = self._query(a,b,k*2+2, (left+right)//2+1, right) vr self._query(a,b,k*2+2, (left+right)//2+1, right) self._query self _query a b k*2+2 k*2 k 2 2 (left+right)//2+1 (left+right)//2 left+right left right 2 1 right return vl | vr vl | vr vl vr self self a a b b k k left left right right def query(self, a, b):
        return self._query(a,b,0,0,self.size-1) query return self._query(a,b,0,0,self.size-1) self._query(a,b,0,0,self.size-1) self._query self _query a b 0 0 self.size-1 self.size self size 1 self self a a b b def resolve():
    N = int(input())
    S = input().strip()
    Q = int(input())
    table = [[] for _ in range(26)]
    sg = SegmentTree(SIZE)
    for i,ch in enumerate(S):
        sg.update(i, ch)

    for i in range(Q):
        query = input().strip().split()
        if query[0] == '1':
            pos = int(query[1])-1
            sg.update(pos, query[2])
        else:
            left = int(query[1])-1
            right = int(query[2])-1
            bits = sg.query(left, right)
            count = 0
            for j in range(26):
                count += (bits>>j) & 1
            print(count) resolve N = int(input()) N int(input()) int input() input S = input().strip() S input().strip() ().strip () input strip Q = int(input()) Q int(input()) int input() input [] for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [] table = [[] for _ in range(26)] table [[] for _ in range(26)] sg = SegmentTree(SIZE) sg SegmentTree(SIZE) SegmentTree SIZE for i,ch in enumerate(S):
        sg.update(i, ch)

     i ch enumerate(S) enumerate S sg.update(i, ch) sg.update sg update i ch for i in range(Q):
        query = input().strip().split()
        if query[0] == '1':
            pos = int(query[1])-1
            sg.update(pos, query[2])
        else:
            left = int(query[1])-1
            right = int(query[2])-1
            bits = sg.query(left, right)
            count = 0
            for j in range(26):
                count += (bits>>j) & 1
            print(count) i range(Q) range Q query = input().strip().split() query input().strip().split() ().strip().split ().strip() ().strip () input strip split if query[0] == '1':
            pos = int(query[1])-1
            sg.update(pos, query[2])
        else:
            left = int(query[1])-1
            right = int(query[2])-1
            bits = sg.query(left, right)
            count = 0
            for j in range(26):
                count += (bits>>j) & 1
            print(count) query[0] == '1' query[0] query 0 '1' pos = int(query[1])-1 pos int(query[1])-1 int(query[1]) int query[1] query 1 1 sg.update(pos, query[2]) sg.update sg update pos query[2] query 2 left = int(query[1])-1 left int(query[1])-1 int(query[1]) int query[1] query 1 1 right = int(query[2])-1 right int(query[2])-1 int(query[2]) int query[2] query 2 1 bits = sg.query(left, right) bits sg.query(left, right) sg.query sg query left right count = 0 count 0 for j in range(26):
                count += (bits>>j) & 1
             j range(26) range 26 count += (bits>>j) & 1 count (bits>>j) & 1 bits>>j bits j 1 print(count) print count resolve() resolve class SegmentTree:
    def __init__(self, size):
        self.size = size
        self.seg = [0] * (2 * size)

    def update(self, pos, ch):
        # update leaf
        i = self.size + pos - 1
        self.seg[i] = 1 << (ord(ch)-ord('a'))
        # update tree
        while i > 0:
            i = (i - 1) // 2
            self.seg[i] = self.seg[i*2+1] | self.seg[i*2+2]

    def _query(self, a, b, k, left, right):
        if right<a or b<left:
            return 0
        if a<=left and right<=b:
            return self.seg[k]

        vl = self._query(a,b,k*2+1, left, (left+right)//2)
        vr = self._query(a,b,k*2+2, (left+right)//2+1, right)
        return vl | vr

    def query(self, a, b):
        return self._query(a,b,0,0,self.size-1) class SegmentTree:
    def __init__(self, size):
        self.size = size
        self.seg = [0] * (2 * size)

    def update(self, pos, ch):
        # update leaf
        i = self.size + pos - 1
        self.seg[i] = 1 << (ord(ch)-ord('a'))
        # update tree
        while i > 0:
            i = (i - 1) // 2
            self.seg[i] = self.seg[i*2+1] | self.seg[i*2+2]

    def _query(self, a, b, k, left, right):
        if right<a or b<left:
            return 0
        if a<=left and right<=b:
            return self.seg[k]

        vl = self._query(a,b,k*2+1, left, (left+right)//2)
        vr = self._query(a,b,k*2+2, (left+right)//2+1, right)
        return vl | vr

    def query(self, a, b):
        return self._query(a,b,0,0,self.size-1) SegmentTree def resolve():
    N = int(input())
    S = input().strip()
    Q = int(input())
    table = [[] for _ in range(26)]
    sg = SegmentTree(SIZE)
    for i,ch in enumerate(S):
        sg.update(i, ch)

    for i in range(Q):
        query = input().strip().split()
        if query[0] == '1':
            pos = int(query[1])-1
            sg.update(pos, query[2])
        else:
            left = int(query[1])-1
            right = int(query[2])-1
            bits = sg.query(left, right)
            count = 0
            for j in range(26):
                count += (bits>>j) & 1
            print(count) def resolve():
    N = int(input())
    S = input().strip()
    Q = int(input())
    table = [[] for _ in range(26)]
    sg = SegmentTree(SIZE)
    for i,ch in enumerate(S):
        sg.update(i, ch)

    for i in range(Q):
        query = input().strip().split()
        if query[0] == '1':
            pos = int(query[1])-1
            sg.update(pos, query[2])
        else:
            left = int(query[1])-1
            right = int(query[2])-1
            bits = sg.query(left, right)
            count = 0
            for j in range(26):
                count += (bits>>j) & 1
            print(count) resolve SIZE = 2**20 2**20 SIZE
SIZE = 2**20 # 2**20 > N=500000

class SegmentTree:
    def __init__(self, size):
        self.size = size
        self.seg = [0] * (2 * size)

    def update(self, pos, ch):
        # update leaf
        i = self.size + pos - 1
        self.seg[i] = 1 << (ord(ch)-ord('a'))
        # update tree
        while i > 0:
            i = (i - 1) // 2
            self.seg[i] = self.seg[i*2+1] | self.seg[i*2+2]

    def _query(self, a, b, k, left, right):
        if right<a or b<left:
            return 0
        if a<=left and right<=b:
            return self.seg[k]

        vl = self._query(a,b,k*2+1, left, (left+right)//2)
        vr = self._query(a,b,k*2+2, (left+right)//2+1, right)
        return vl | vr

    def query(self, a, b):
        return self._query(a,b,0,0,self.size-1)


def resolve():
    N = int(input())
    S = input().strip()
    Q = int(input())
    table = [[] for _ in range(26)]
    sg = SegmentTree(SIZE)
    for i,ch in enumerate(S):
        sg.update(i, ch)

    for i in range(Q):
        query = input().strip().split()
        if query[0] == '1':
            pos = int(query[1])-1
            sg.update(pos, query[2])
        else:
            left = int(query[1])-1
            right = int(query[2])-1
            bits = sg.query(left, right)
            count = 0
            for j in range(26):
                count += (bits>>j) & 1
            print(count)

resolve()