You are given a string $s$ consisting of lowercase Latin letters and $q$ queries for this string.

Recall that the substring $s[l; r]$ of the string $s$ is the string $s_l s_{l + 1} \dots s_r$. For example, the substrings of "codeforces" are "code", "force", "f", "for", but not "coder" and "top".

There are two types of queries:   $1~ pos~ c$ ($1 \le pos \le |s|$, $c$ is lowercase Latin letter): replace $s_{pos}$ with $c$ (set $s_{pos} := c$);  $2~ l~ r$ ($1 \le l \le r \le |s|$): calculate the number of distinct characters in the substring $s[l; r]$. 


-----Input-----

The first line of the input contains one string $s$ consisting of no more than $10^5$ lowercase Latin letters.

The second line of the input contains one integer $q$ ($1 \le q \le 10^5$) — the number of queries.

The next $q$ lines contain queries, one per line. Each query is given in the format described in the problem statement. It is guaranteed that there is at least one query of the second type.


-----Output-----

For each query of the second type print the answer for it — the number of distinct characters in the required substring in this query.


-----Examples-----
Input
abacaba
5
2 1 4
1 4 b
1 5 b
2 4 6
2 1 7

Output
3
1
2

Input
dfcbbcfeeedbaea
15
1 6 e
1 4 b
2 6 14
1 7 b
1 12 c
2 6 8
2 1 6
1 7 c
1 2 f
1 10 a
2 7 9
1 10 a
1 14 b
1 1 f
2 1 11

Output
5
2
5
2
6

Difficulty: introductory

Starter code:

Solutions:
# -*- coding: utf-8 -*-

import sys
from operator import add

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class SegTree:
 
    def __init__(self, n, func, init):

        self.n = n
        self.func = func
        self.init = init

        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [self.init] * (n2 << 1)
 
    def update(self, i, x):

        i += self.n2
        self.tree[i] = x
        while i > 1:
            self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])
            i >>= 1
 
    def query(self, a, b):

        l = a + self.n2
        r = b + self.n2
        s = self.init
        while l < r:
            if r & 1:
                r -= 1
                s = self.func(s, self.tree[r])
            if l & 1:
                s = self.func(s, self.tree[l])
                l += 1
            l >>= 1
            r >>= 1
        return s

A = [ord(s)-97 for s in list(input())]
N = len(A)

st = [None] * 26
for i in range(26):
    st[i] = SegTree(N, add, 0)
for i, a in enumerate(A):
    st[a].update(i, 1)

for _ in range(INT()):
    a, b, c = input().split()
    if a == '1':
        b = int(b)
        cur = A[b-1]
        nxt = ord(c) - 97
        st[cur].update(b-1, 0)
        st[nxt].update(b-1, 1)
        A[b-1] = nxt
    else:
        b = int(b)
        c = int(c)
        cnt = 0
        for i in range(26):
            if st[i].query(b-1, c) >= 1:
                cnt += 1
        print(cnt)


import heapq
import math

import sys
input = sys.stdin.readline

def li():return [int(i) for i in input().rstrip('\n').split()]
def value():return int(input())


def givesum(a,b):
    c=[0]*26
    for i in range(len(a)):
        c[i] = a[i]+b[i]
    return c
def dolist(a):
    c = [0]*26
    c[ord(a)-ord('a')] = 1
    return c
    
class Node:
    def __init__(self,s,e):
        self.start=s
        self.end=e
        self.lis=[0]*26
        self.left=None
        self.right=None

def build(nums,l,r):
    if l == r:
        temp = Node(l,l)
        # print(temp.start,ord(nums[l])-ord('a'),nums)
        temp.lis[ord(nums[l])-ord('a')] = 1
    else:
        mid=(l+r)>>1
        # print(mid,l,r)
        temp=Node(l,r)
        temp.left=build(nums,l,mid)
        temp.right=build(nums,mid+1,r)
        temp.lis=givesum(temp.left.lis,temp.right.lis)
    return temp

def update(root,start,value):
    if root.start==root.end==start:
        root.lis=dolist(value)
    elif root.start<=start and root.end>=start:
        mid=(root.start+root.end)>>1
        root.left=update(root.left,start,value)
        root.right=update(root.right,start,value)
        root.lis=givesum(root.left.lis,root.right.lis)
    return root
    
def query(root,start,end):
    if root.start>=start and root.end<=end:return root.lis
    elif root.start>end or root.end<start:return [0]*26;
    else:
        mid=(start+end)>>1
        return givesum(query(root.left,start,end),query(root.right,start,end))
        
s = input().rstrip('\n')
root = build(s,0,len(s)-1)
ansarun = []
# print('arun')
for _ in range(int(input())):
    templist = list(input().split())
    if templist[0] == '1':
        root = update(root,int(templist[1])-1,templist[2])
    else:
        temp1 = query(root,int(templist[1])-1,int(templist[2])-1)
        total = 0
        for i in temp1:
            if i:total+=1
        ansarun.append(total)
for i in ansarun:print(i)
    
    
    
    


from string import ascii_lowercase as lows
import sys

input = sys.stdin.readline

N = (1<<17)

class bit:
    def __init__( self ):
        self.l = [0]*(1 + N)
    def set( self, i ):
        self.add( i, 1 )
    def unset( self, i ):
        self.add( i, -1 )
    def add( self, i, val ):
        while i <= N:
            self.l[ i ] += val
            i += (i & (-i))
    def get( self, i ):
        r = 0
        while i > 0:
            r += self.l[ i ]
            i -= (i & (-i))
        return r
    def range( self, l, r ):
        return self.get( r ) - self.get( l - 1 )

bits = { c: bit() for c in lows }

s = [ c for c in input().strip() ]
for i, c in enumerate(s):
    bits[ c ].set( i + 1 )
q = int(input().strip())

for _ in range(q):
    ins = input().split()
    if ins[ 0 ] == '1':
        pos = int( ins[ 1 ] )
        bits[ s[ pos - 1 ] ].unset( pos )
        bits[ ins[ 2 ] ].set( pos )
        s[ pos - 1 ] = ins[ 2 ]
    else:
        l, r = list(map(int, ins[1:] ))
        sm = 0
        for b in list(bits.values()):
            if b.range( l, r ) > 0:
                sm += 1
        print( sm )


from string import ascii_lowercase as lows
import sys

input = sys.stdin.readline

s = [ c for c in input().strip() ]
N = len(s)

class bit:
    def __init__( self ):
        self.l = [0]*(1 + N)
    def set( self, i ):
        self.add( i, 1 )
    def unset( self, i ):
        self.add( i, -1 )
    def add( self, i, val ):
        while i <= N:
            self.l[ i ] += val
            i += (i & (-i))
    def get( self, i ):
        r = 0
        while i > 0:
            r += self.l[ i ]
            i -= (i & (-i))
        return r
    def range( self, l, r ):
        return self.get( r ) - self.get( l - 1 )

bits = { c: bit() for c in lows }

for i, c in enumerate(s):
    bits[ c ].set( i + 1 )
q = int(input().strip())

for _ in range(q):
    ins = input().split()
    if ins[ 0 ] == '1':
        pos = int( ins[ 1 ] )
        bits[ s[ pos - 1 ] ].unset( pos )
        bits[ ins[ 2 ] ].set( pos )
        s[ pos - 1 ] = ins[ 2 ]
    else:
        l, r = list(map(int, ins[1:] ))
        sm = 0
        for b in list(bits.values()):
            if b.range( l, r ) > 0:
                sm += 1
        print( sm )


s=input()
q=int(input())
T=[]
for i in range(4*len(s)+10):
    T.append(0)

def create(rt,l,r):
    if(l==r):
        T[rt]=1<<(ord(s[l-1])-97)
        return
    mid=(l+r)//2
    create(rt<<1,l,mid)
    create(rt<<1|1,mid+1,r)
    T[rt]=T[rt<<1]|T[rt<<1|1]

def update(rt,l,r,pos,now):
    if(l==r):
        T[rt]=1<<(ord(now)-97)
        return
    mid=(l+r)//2
    if(pos<=mid):
        update(rt<<1,l,mid,pos,now)
    else:
        update(rt<<1|1,mid+1,r,pos,now)
    T[rt]=T[rt<<1]|T[rt<<1|1]

def cal(rt,l,r,L,R):
    if(l==L and R==r):
        return T[rt]
    mid=(l+r)//2
    if(R<=mid):
        return cal(rt<<1,l,mid,L,R)
    elif(L>mid):
        return cal(rt<<1|1,mid+1,r,L,R)
    else:
        return cal(rt<<1,l,mid,L,mid)|cal(rt<<1|1,mid+1,r,mid+1,R)

n=len(s)
create(1,1,n)

for i in range(q):
    str=input().split()
    if(str[0]=='1'):
        pos=int(str[1])
        update(1,1,n,pos,str[2])
    else:
        l=int(str[1])
        r=int(str[2])
        res=cal(1,1,n,l,r)
        ans=0
        while(res>0):
            if(res%2==1):
                ans+=1
            res//=2
        print(ans)

def update(v,w,s):
    
    while v<=length:
        l[s][v]+=w
        v+=(v&(-v))
def get_value(v,s):
    ans=0
    
    while v!=0:
        
        ans+=l[s][v]
        v-=(v&(-v))
    return ans
from sys import stdin,stdout
s=list(stdin.readline().strip())
q=int(stdin.readline())
length=len(s)
l=[[0 for i in range(length+1)] for _ in range(26)]

for i in range(length):
    x=ord(s[i])-97
    update(i+1,1,x)

for _ in range(q):
    
    n,m,k=stdin.readline().split()
    if n=='1':
        a=s[int(m)-1]
        x,y=ord(a)-97,ord(k)-97
        update(int(m),-1,x)
        update(int(m),1,y)
        s[int(m)-1]=k
        
    else:
        count=0
        left,r=int(m),int(k)
        for i in range(26):
            if get_value(r,i)-get_value(left-1,i)>=1:
                
                count+=1
        print(count)
        



from sys import stdin,stdout

R = lambda: map(int, input().split())
S = list(stdin.readline().strip())
Q = int(input())
n = len(S)
S = list(S)
sum_array = [[0] * (n+1) for _ in range(26)]


def lowbit(x):
    return x & -x

def add(x, val, idx):
    while x <= n:
        sum_array[idx][x] += val
        x += lowbit(x)

def sum(x, idx):
    res = 0
    while x > 0:
        res += sum_array[idx][x]
        x -= lowbit(x)
    return res


for i in range(n):
    idx = ord(S[i]) - 97
    add(i+1, 1, idx)

for _ in range(Q):
    A = stdin.readline().split()
    a, b, c = int(A[0]), int(A[1]), A[2]
    if a == 1:
        pre = ord(S[b-1]) - 97
        cur = ord(c) - 97
        S[b-1] = c
        add(b, -1, pre)
        add(b, 1, cur)
    else:
        c = int(c)
        if c - b == 0:
            print(1)
        else:
            res = 0
            for i in range(26):
                diff = sum(c, i) - sum(b-1, i)
                res += int(diff > 0)
            print(res)

def update(v,w,s):
    
    while v<=length:
        l[s][v]+=w
        v+=(v&(-v))
def get_value(v,s):
    ans=0
    
    while v!=0:
        
        ans+=l[s][v]
        v-=(v&(-v))
    return ans
from sys import stdin,stdout
s=list(stdin.readline().strip())
q=int(stdin.readline())
length=len(s)
l=[[0 for i in range(length+1)] for _ in range(26)]

for i in range(length):
    x=ord(s[i])-97
    update(i+1,1,x)

for _ in range(q):
    
    n,m,k=stdin.readline().split()
    if n=='1':
        a=s[int(m)-1]
        x,y=ord(a)-97,ord(k)-97
        update(int(m),-1,x)
        update(int(m),1,y)
        s[int(m)-1]=k
        
    else:
        count=0
        left,r=int(m),int(k)
        for i in range(26):
            if get_value(r,i)-get_value(left-1,i)>=1:
                
                count+=1
        print(count)


#test
s  = list(input())
t = [0 for i in range(len(s)*4)]
bits = dict()
b = 1
for i in range(97, 123):
    bits[chr(i)] = b
    b<<=1
def bit_repr(a):
    return bits[a]

def popcount(i):
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

def build(A, v, t_left, t_right):
    if t_left == t_right:
        t[v] |= bit_repr(A[t_left])
        return
    left_son = (v<<1) + 1
    right_son = left_son + 1
    t_mid = (t_left + t_right)>>1
    build(A, left_son, t_left, t_mid)
    build(A, right_son, t_mid+1, t_right)
    t[v] = t[left_son] | t[right_son]
 
def _update(v, t_left, t_right, index, val):
    while t_left != t_right:
        t_mid = (t_left + t_right)//2
        left_son = (v<<1) + 1
        right_son = left_son + 1
        if index > t_mid:
            t_left = t_mid+1
            v = right_son
        else:
            t_right = t_mid
            v = left_son
    t[v] = bit_repr(val)
    while v:
        v = (v-1)>>1
        left_son = (v<<1) + 1
        right_son = left_son + 1
        t[v] = t[left_son] | t[right_son]
 
def update(index, val):
    _update(0, 0, len(s)-1, index-1, val)
 
def get_set(v, t_left, t_right, left, right):
    if left>right:
        return 0
    if t_left == left and t_right == right:
        return t[v]
    t_mid = (t_left+t_right)>>1
    left_son = (v<<1) + 1
    right_son = left_son + 1
    a = get_set(left_son, t_left, t_mid, left, min(right, t_mid))
    b = get_set(right_son, t_mid+1, t_right, max(left, t_mid+1), right)
    return a|b
 
def count(l, r):
    return popcount(get_set(0, 0, len(s)-1, l-1, r-1))
 
def get_request():
    req = iter(input().split())
    token = int(next(req))
    if token-1: #count
        l, r = list(map(int, req))
        return token, l, r
    else:       #change
        pos = int(next(req))
        sym = next(req)
        return token, pos, sym
 
def response(req):
    token, a, b = req
    if token - 1: #count
        print(count(a,b))
    else:
        update(a, b)
 

build(s,0,0,len(s)-1)
n = int(input())
for i in range(n):
    req = get_request()
    response(req)


#last solution was AC with 1965 ms
# Test 2
s  = list(input())
t = [0 for i in range(len(s)*4)]
bits = dict()
b = 1
for i in range(97, 123):
    bits[chr(i)] = b
    b<<=1
def bit_repr(a):
    return bits[a]

def popcount(i):
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

def build(A, v, t_left, t_right):
    if t_left == t_right:
        t[v] |= bit_repr(A[t_left])
        return
    left_son = (v<<1) + 1
    right_son = left_son + 1
    t_mid = (t_left + t_right)>>1
    build(A, left_son, t_left, t_mid)
    build(A, right_son, t_mid+1, t_right)
    t[v] = t[left_son] | t[right_son]
 
def _update(v, t_left, t_right, index, val):
    while t_left != t_right:
        t_mid = (t_left + t_right)//2
        left_son = (v<<1) + 1
        right_son = left_son + 1
        if index > t_mid:
            t_left = t_mid+1
            v = right_son
        else:
            t_right = t_mid
            v = left_son
    t[v] = bit_repr(val)
    while v:
        v = (v-1)>>1
        left_son = (v<<1) + 1
        right_son = left_son + 1
        t[v] = t[left_son] | t[right_son]
 
def update(index, val):
    _update(0, 0, len(s)-1, index-1, val)
 
def get_set(v, t_left, t_right, left, right):
    if left>right:
        return 0
    if t_left == left and t_right == right:
        return t[v]
    t_mid = (t_left+t_right)>>1
    left_son = (v<<1) + 1
    right_son = left_son + 1
    a = get_set(left_son, t_left, t_mid, left, min(right, t_mid))
    b = get_set(right_son, t_mid+1, t_right, max(left, t_mid+1), right)
    return a|b
 
def count(l, r):
    return popcount(get_set(0, 0, len(s)-1, l-1, r-1))
 
def get_request():
    req = iter(input().split())
    token = int(next(req))
    if token-1: #count
        l, r = list(map(int, req))
        return token, l, r
    else:       #change
        pos = int(next(req))
        sym = next(req)
        return token, pos, sym
 
def response(req):
    token, a, b = req
    if token - 1: #count
        print(count(a,b))
    else:
        update(a, b)
 

build(s,0,0,len(s)-1)
n = int(input())
for i in range(n):
    req = get_request()
    response(req)


# Test 3

#basic input
s  = input()
n = int(input())
t = [0 for i in range(len(s)*4)]

#precalculating masks
bits = dict()
b = 1
for i in range(97, 123):
    bits[chr(i)] = b
    b<<=1

def bit_repr(a):
    return bits[a]

def popcount(i):
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

def build(A, v, t_left, t_right):

    if t_left == t_right:
        t[v] |= bit_repr(A[t_left])
        return

    left_son = (v<<1) + 1
    right_son = left_son + 1
    t_mid = (t_left + t_right)>>1

    build(A, left_son, t_left, t_mid)
    build(A, right_son, t_mid+1, t_right)

    t[v] = t[left_son] | t[right_son]
 
def _update(v, t_left, t_right, index, val):
    #find destination
    while t_left != t_right:
        t_mid = (t_left + t_right)>>1
        left_son = (v<<1) + 1
        right_son = left_son + 1
        if index > t_mid:
            t_left = t_mid+1
            v = right_son
        else:
            t_right = t_mid
            v = left_son
    #change val
    t[v] = bit_repr(val)
    #update upper nodes
    while v:
        v = (v-1)>>1
        left_son = (v<<1) + 1
        right_son = left_son + 1
        t[v] = t[left_son] | t[right_son]
 
def get_set(v, t_left, t_right, left, right):
    if left > right:
        return 0
    if t_left == left and t_right == right:
        return t[v]
    t_mid = (t_left+t_right)>>1
    
    left_son = (v<<1) + 1
    right_son = left_son + 1

    a = get_set(left_son, t_left, t_mid, left, min(right, t_mid))
    b = get_set(right_son, t_mid+1, t_right, max(left, t_mid+1), right)

    return a|b
 


def update(index, val):
    '''Interface for _update function'''
    _update(0, 0, len(s)-1, index-1, val)

def count(l, r):
    '''Interface for popcount(get_set())'''
    return popcount(get_set(0, 0, len(s)-1, l-1, r-1))

def process():
    req = iter(input().split())
    token = int(next(req))
    if token-1:                     #count
        l, r = list(map(int, req))
        print(count(l, r))
    else:                           #change
        pos = int(next(req))
        sym = next(req)
        update(pos, sym)

build(s, 0, 0, len(s)-1)

#request - response part
for i in range(n):
    process()


import math
import bisect
from functools import reduce
import sys
from collections import defaultdict
input=sys.stdin.readline
def inn():
    return int(input())
 
def inl():
    return list(map(int, input().split()))
 
MOD = 10**9+7
INF = inf = 10**18+5
 
s = list(input().strip())
n = len(s)
t = [[0]*26 for i in range(2*n)]
 
for i in range(n):
    t[i+n][ord(s[i])-97] = 1
 
def build():
    for i in range(n-1, 0, -1):
        for j in range(26):
            t[i][j] = t[i<<1][j] + t[i<<1|1][j]
 
def modify(p, val):
    t[p+n][ord(s[p])-97] = 0
    t[p+n][ord(val)-97] = 1
    s[p] = val
    p = p+n
    while p>1:
        for i in range(26):
            t[p>>1][i] = t[p][i] + t[p^1][i]
        p >>= 1
 
def query(l, r):
    res = [0]*26
    l += n
    r += n
    while l<r:
        if l&1:
            for i in range(26):
                res[i] += t[l][i]
            l += 1
        if r&1:
            r -= 1
            for i in range(26):
                res[i] += t[r][i]
        l >>= 1
        r >>= 1
    return res
 
build()
 
for q in range(inn()):
    tp, l, r = input().split()
    tp = int(tp)
    l = int(l)
    if tp==1:
        modify(l-1, r)
    elif tp==2:
        r = int(r)
        res = query(l-1, r)
        c = len([i for i in range(26) if res[i]>0])
        print(c)
    # print(t)


import sys
input = sys.stdin.readline

S = list(input().rstrip())
L = len(S)
Q = int(input())
data = []
for _ in range(Q):
    A = list(map(str, input().split()))
    data.append(A)

alp = [chr(i) for i in range(97, 97+26)]
BITs = {}
for a in alp:
    BITs[a] = [0]*(L+1)

def query_sum(i, al):
    s = 0
    while i > 0:
        s += BITs[al][i]
        i -= i & -i
    return s

def add(i, x, al):
    while i <= L:
        BITs[al][i] += x
        i += i & -i

def main():
    for i, s in enumerate(S):
        add(i+1, 1, s)

    for A in data:
        if A[0] == '1':
            l, s = int(A[1]), A[2]
            for al in alp:
                if query_sum(l, al) - query_sum(l-1, al) == 1:
                    add(l, -1, al)
                    break
            add(l, 1, s)
        else:
            l, r = int(A[1]), int(A[2])
            c = 0
            for al in alp:
                if query_sum(r, al) - query_sum(l-1, al) > 0:
                    c += 1
            print(c)

def __starting_point():
    main()
__starting_point()

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class SegmentTree():
    def __init__(self, n):
        self.n = 2**(n-1).bit_length()
        self.data = [0 for _ in range(2*self.n)]

    def set(self, k, v):
        v_val = ord(v)-ord('a')
        self.data[k+self.n-1] = 1 << v_val

    def build(self):
        for k in reversed(list(range(self.n-1))):
            self.data[k] = self.data[k*2+1] | self.data[k*2+2]

    def update(self, k, a):
        k += self.n-1
        v_val = ord(a)-ord("a")
        self.data[k] = 1 << v_val

        while k > 0:
            k = (k-1)//2
            self.data[k] = self.data[k*2+1] | self.data[k*2+2]

    def query(self, l, r):
        L = l+self.n
        R = r+self.n
        ret = 0
        while L < R:
            if R & 1:
                R -= 1
                ret |= self.data[R-1]
            if L & 1:
                ret |= self.data[L-1]
                L += 1
            L >>= 1
            R >>= 1
        return ret


S = [v for v in input()[:-1]]
N = len(S)
Q = int(input())
query = [[v for v in input()[:-1].split()] for _ in range(Q)]

Seg = SegmentTree(N)
for i, s in enumerate(S):
    Seg.set(i, s)

Seg.build()

for q, v1, v2 in query:
    if q == "1":
        Seg.update(int(v1)-1, v2)
    else:
        val = Seg.query(int(v1)-1, int(v2))
        print(bin(val)[2:].count("1"))


import math
import bisect
from functools import reduce
from collections import defaultdict
import sys
input = sys.stdin.readline

def inn():
    return int(input())

def inl():
    return list(map(int, input().split()))

MOD = 10**9+7
INF = inf = 10**18+5

s = list(input().strip())
n = len(s)
t = [[0]*26 for i in range(2*n)]

for i in range(n):
	t[i+n][ord(s[i])-97] = 1

def build():
	for i in range(n-1, 0, -1):
		for j in range(26):
			t[i][j] = t[i<<1][j] + t[i<<1|1][j]

def modify(p, val):
	t[p+n][ord(s[p])-97] = 0
	t[p+n][ord(val)-97] = 1
	s[p] = val
	p = p+n
	while p>1:
		for i in range(26):
			t[p>>1][i] = t[p][i] + t[p^1][i]
		p >>= 1

def query(l, r):
	res = [0]*26
	l += n
	r += n
	while l<r:
		if l&1:
			for i in range(26):
				res[i] += t[l][i]
			l += 1
		if r&1:
			r -= 1
			for i in range(26):
				res[i] += t[r][i]
		l >>= 1
		r >>= 1
	return res

build()

for q in range(inn()):
	tp, l, r = input().split()
	tp = int(tp)
	l = int(l)
	if tp==1:
		modify(l-1, r)
	elif tp==2:
		r = int(r)
		res = query(l-1, r)
		c = len([i for i in range(26) if res[i]>0])
		print(c)
	# print(t)


import sys

input = sys.stdin.readline

class SegmentTree:
    a = ord('a')

    def __init__(self):
        data = [1 << ord(c) - self.a for c in input()[:-1]]

        self.n = 1 << len(bin(len(data) - 1)) - 2
        self.data = [0] * self.n + data + [0] * (self.n - len(data))

        for k in range(self.n - 1, 0, -1):
            self.data[k] = self.data[2 * k + 1] | self.data[2 * k]

    def update(self, k, c):
        k += self.n
        self.data[k] = 1 << ord(c) - self.a

        while k > 1:
            k >>= 1
            self.data[k] = self.data[2 * k + 1] | self.data[2 * k]

    def query(self, l, r):
        l += self.n
        r += self.n
        s = self.data[r] | self.data[l]

        while l < r - 1:
            if r & 1: s |= self.data[r - 1]
            if not l & 1: s |= self.data[l + 1]
            l >>= 1
            r >>= 1
        return s

tree = SegmentTree()

for i in range(int(input())):
    q = input()[:-1].split()
    if q[0] == "1":
        tree.update(int(q[1]) - 1, q[2])
    else:
        s = tree.query(int(q[1]) - 1, int(q[2]) - 1)
        print(bin(s)[2:].count("1"))