class BinaryIndexedTree():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        self.depth = self.size.bit_length()
 
    def initialize(self, seq):
        for i, x in enumerate(seq[1:], 1):
            self.tree[i] += x
            j = i + (i & (-i))
            if j < self.size:
                self.tree[j] += self.tree[i]
 
    def __repr__(self):
        return self.tree.__repr__()
 
    def get_sum(self, i):
        s = 0
        while i:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i < self.size:
            self.tree[i] += x
            i += i & -i
 
    def find_kth_element(self, k):
        x, sx = 0, 0
        dx = (1 << self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= self.size:
                continue
            y = x + dx
            sy = sx + self.tree[y]
            if sy < k:
                x, sx = y, sy
        return x + 1



n = int(input())
s = ["!"]+list(input())
q = int(input())
bit = [BinaryIndexedTree(n+1) for i in range(26)]

for i in range(n):
    ind = ord(s[i+1])-97
    bit[ind].add(i+1,1)

for i in range(q):
    a,b,c = input().split()
    b = int(b)
    if a == "1":
        ind = ord(s[b])-97
        bit[ind].add(b,-1)
        ind = ord(c)-97
        bit[ind].add(b,1)
        s[b] = c
    else:
        ans = 0
        c = int(c)
        for i in range(26):
            if bit[i].get_sum(c)-bit[i].get_sum(b-1):
                ans += 1
        print(ans) class BinaryIndexedTree():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        self.depth = self.size.bit_length()
 
    def initialize(self, seq):
        for i, x in enumerate(seq[1:], 1):
            self.tree[i] += x
            j = i + (i & (-i))
            if j < self.size:
                self.tree[j] += self.tree[i]
 
    def __repr__(self):
        return self.tree.__repr__()
 
    def get_sum(self, i):
        s = 0
        while i:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i < self.size:
            self.tree[i] += x
            i += i & -i
 
    def find_kth_element(self, k):
        x, sx = 0, 0
        dx = (1 << self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= self.size:
                continue
            y = x + dx
            sy = sx + self.tree[y]
            if sy < k:
                x, sx = y, sy
        return x + 1 BinaryIndexedTree def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        self.depth = self.size.bit_length()
 
     __init__ self.size = max_n + 1 self.size self size max_n + 1 max_n 1 self.tree = [0] * self.size self.tree self tree [0] * self.size [0] 0 self.size self size self.depth = self.size.bit_length() self.depth self depth self.size.bit_length() self.size.bit_length self.size self size bit_length self self max_n max_n def initialize(self, seq):
        for i, x in enumerate(seq[1:], 1):
            self.tree[i] += x
            j = i + (i & (-i))
            if j < self.size:
                self.tree[j] += self.tree[i]
 
     initialize for i, x in enumerate(seq[1:], 1):
            self.tree[i] += x
            j = i + (i & (-i))
            if j < self.size:
                self.tree[j] += self.tree[i]
 
     i x enumerate(seq[1:], 1) enumerate seq[1:] seq 1: 1 1 self.tree[i] += x self.tree[i] self.tree self tree i x j = i + (i & (-i)) j i + (i & (-i)) i i & (-i) i -i i if j < self.size:
                self.tree[j] += self.tree[i]
 
     j < self.size j self.size self size self.tree[j] += self.tree[i] self.tree[j] self.tree self tree j self.tree[i] self.tree self tree i self self seq seq def __repr__(self):
        return self.tree.__repr__()
 
     __repr__ return self.tree.__repr__() self.tree.__repr__() self.tree.__repr__ self.tree self tree __repr__ self self def get_sum(self, i):
        s = 0
        while i:
            s += self.tree[i]
            i -= i & -i
        return s
 
     get_sum s = 0 s 0 while i:
            s += self.tree[i]
            i -= i & -i
         i 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):
        while i < self.size:
            self.tree[i] += x
            i += i & -i
 
     add 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 find_kth_element(self, k):
        x, sx = 0, 0
        dx = (1 << self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= self.size:
                continue
            y = x + dx
            sy = sx + self.tree[y]
            if sy < k:
                x, sx = y, sy
        return x + 1 find_kth_element x, sx = 0, 0 x 0 sx 0 dx = (1 << self.depth) dx 1 << self.depth 1 self.depth self depth for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= self.size:
                continue
            y = x + dx
            sy = sx + self.tree[y]
            if sy < k:
                x, sx = y, sy
         i range(self.depth - 1, -1, -1) range self.depth - 1 self.depth self depth 1 -1 -1 dx = (1 << i) dx 1 << i 1 i if x + dx >= self.size:
                continue
             x + dx >= self.size x + dx x dx self.size self size continue y = x + dx y x + dx x dx sy = sx + self.tree[y] sy sx + self.tree[y] sx self.tree[y] self.tree self tree y if sy < k:
                x, sx = y, sy
         sy < k sy k x, sx = y, sy x y sx sy return x + 1 x + 1 x 1 self self k k n = int(input()) n int(input()) int input() input s = ["!"]+list(input()) s ["!"]+list(input()) ["!"] "!" list(input()) list input() input q = int(input()) q int(input()) int input() input BinaryIndexedTree(n+1) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) BinaryIndexedTree(n+1) BinaryIndexedTree n+1 n 1 bit = [BinaryIndexedTree(n+1) for i in range(26)] bit [BinaryIndexedTree(n+1) for i in range(26)] for i in range(n):
    ind = ord(s[i+1])-97
    bit[ind].add(i+1,1) i range(n) range n ind = ord(s[i+1])-97 ind ord(s[i+1])-97 ord(s[i+1]) ord s[i+1] s i+1 i 1 97 bit[ind].add(i+1,1) [ind].add [ind] bit ind add i+1 i 1 1 for i in range(q):
    a,b,c = input().split()
    b = int(b)
    if a == "1":
        ind = ord(s[b])-97
        bit[ind].add(b,-1)
        ind = ord(c)-97
        bit[ind].add(b,1)
        s[b] = c
    else:
        ans = 0
        c = int(c)
        for i in range(26):
            if bit[i].get_sum(c)-bit[i].get_sum(b-1):
                ans += 1
        print(ans) i range(q) range q a,b,c = input().split() a input().split() ().split () input split b c b = int(b) b int(b) int b if a == "1":
        ind = ord(s[b])-97
        bit[ind].add(b,-1)
        ind = ord(c)-97
        bit[ind].add(b,1)
        s[b] = c
    else:
        ans = 0
        c = int(c)
        for i in range(26):
            if bit[i].get_sum(c)-bit[i].get_sum(b-1):
                ans += 1
        print(ans) a == "1" a "1" ind = ord(s[b])-97 ind ord(s[b])-97 ord(s[b]) ord s[b] s b 97 bit[ind].add(b,-1) [ind].add [ind] bit ind add b -1 ind = ord(c)-97 ind ord(c)-97 ord(c) ord c 97 bit[ind].add(b,1) [ind].add [ind] bit ind add b 1 s[b] = c s[b] s b c ans = 0 ans 0 c = int(c) c int(c) int c for i in range(26):
            if bit[i].get_sum(c)-bit[i].get_sum(b-1):
                ans += 1
         i range(26) range 26 if bit[i].get_sum(c)-bit[i].get_sum(b-1):
                ans += 1
         bit[i].get_sum(c)-bit[i].get_sum(b-1) bit[i].get_sum(c) [i].get_sum [i] bit i get_sum c bit[i].get_sum(b-1) [i].get_sum [i] bit i get_sum b-1 b 1 ans += 1 ans 1 print(ans) print ans b = int(b) int(b) b s = ["!"]+list(input()) ["!"]+list(input()) s class BinaryIndexedTree():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        self.depth = self.size.bit_length()
 
    def initialize(self, seq):
        for i, x in enumerate(seq[1:], 1):
            self.tree[i] += x
            j = i + (i & (-i))
            if j < self.size:
                self.tree[j] += self.tree[i]
 
    def __repr__(self):
        return self.tree.__repr__()
 
    def get_sum(self, i):
        s = 0
        while i:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i < self.size:
            self.tree[i] += x
            i += i & -i
 
    def find_kth_element(self, k):
        x, sx = 0, 0
        dx = (1 << self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= self.size:
                continue
            y = x + dx
            sy = sx + self.tree[y]
            if sy < k:
                x, sx = y, sy
        return x + 1 class BinaryIndexedTree():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        self.depth = self.size.bit_length()
 
    def initialize(self, seq):
        for i, x in enumerate(seq[1:], 1):
            self.tree[i] += x
            j = i + (i & (-i))
            if j < self.size:
                self.tree[j] += self.tree[i]
 
    def __repr__(self):
        return self.tree.__repr__()
 
    def get_sum(self, i):
        s = 0
        while i:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i < self.size:
            self.tree[i] += x
            i += i & -i
 
    def find_kth_element(self, k):
        x, sx = 0, 0
        dx = (1 << self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= self.size:
                continue
            y = x + dx
            sy = sx + self.tree[y]
            if sy < k:
                x, sx = y, sy
        return x + 1 BinaryIndexedTree c = input().split() input().split() c ind = ord(s[b])-97 ord(s[b])-97 ind ind = ord(s[i+1])-97 ord(s[i+1])-97 ind ans = 0 0 ans b,c = input().split() input().split() b ind = ord(c)-97 ord(c)-97 ind bit = [BinaryIndexedTree(n+1) for i in range(26)] [BinaryIndexedTree(n+1) for i in range(26)] bit n = int(input()) int(input()) n q = int(input()) int(input()) q c = int(c) int(c) c a,b,c = input().split() input().split() a ans += 1 1 ans
class BinaryIndexedTree():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        self.depth = self.size.bit_length()
 
    def initialize(self, seq):
        for i, x in enumerate(seq[1:], 1):
            self.tree[i] += x
            j = i + (i & (-i))
            if j < self.size:
                self.tree[j] += self.tree[i]
 
    def __repr__(self):
        return self.tree.__repr__()
 
    def get_sum(self, i):
        s = 0
        while i:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i < self.size:
            self.tree[i] += x
            i += i & -i
 
    def find_kth_element(self, k):
        x, sx = 0, 0
        dx = (1 << self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= self.size:
                continue
            y = x + dx
            sy = sx + self.tree[y]
            if sy < k:
                x, sx = y, sy
        return x + 1



n = int(input())
s = ["!"]+list(input())
q = int(input())
bit = [BinaryIndexedTree(n+1) for i in range(26)]

for i in range(n):
    ind = ord(s[i+1])-97
    bit[ind].add(i+1,1)

for i in range(q):
    a,b,c = input().split()
    b = int(b)
    if a == "1":
        ind = ord(s[b])-97
        bit[ind].add(b,-1)
        ind = ord(c)-97
        bit[ind].add(b,1)
        s[b] = c
    else:
        ans = 0
        c = int(c)
        for i in range(26):
            if bit[i].get_sum(c)-bit[i].get_sum(b-1):
                ans += 1
        print(ans)