import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline N,Q=map(int,input().split()) C=[[0,0],[0,1],[0,2],[0,3],[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]] AA=[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (0, 9), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (2, 7), (2, 8), (2, 9), (3, 9), (4, 4), (4, 5), (4, 6), (4, 7), (4, 8), (4, 9), (5, 7), (5, 8), (5, 9), (6, 9), (7, 7), (7, 8), (7, 9), (8, 9), (9, 9)] AX=[[0, 0, 0, 0, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1, 1, 1], [1, 1, 0, 0, 1, 0, 0, 0, 0, 1], [1, 1, 1, 0, 1, 1, 0, 1, 0, 0]] LIST=[[-1]*4 for i in range(4)] for i in range(len(C)): x,y=C[i] LIST[x][y]=i def seg_function(x,y): # Segment treeで扱うfunction ANS=[1<<30]*10 for i,j in AA: a,b=C[i] c,d=C[j] if b<=c: k=LIST[a][d] ANS[k]=min(ANS[k],x[i]+y[j]) return ANS seg_el=1<<(N.bit_length()) # Segment treeの台の要素数 SEG=[1<<30]*(10*(2*seg_el)) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化 def update(n,x,seg_el): # A[n]をxへ更新 i=n+seg_el SEG[i*10:i*10+10]=x i>>=1 # 子ノードへ while i!=0: SEG[i*10:i*10+10]=seg_function(SEG[i*2*10:i*2*10+10],SEG[(i*2+1)*10:(i*2+1)*10+10]) i>>=1 def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる L=l+seg_el R=r+seg_el ANS1=[0]*10 ANS2=[0]*10 while L>=1 R>>=1 return seg_function(ANS1, ANS2) S=input().strip() for i in range(N): # Aを対応する箇所へupdate SEG[(i+seg_el)*10:(i+seg_el)*10+10]=AX[S[i]-65] for i in range(seg_el-1,0,-1): # 親の部分もupdate SEG[i*10:i*10+10]=seg_function(SEG[i*2*10:i*2*10+10],SEG[(i*2+1)*10:(i*2+1)*10+10]) LANS=[] for tests in range(Q): x,y,z=input().split() if int(x)==1: y=int(y)-1 update(y,AX[z[0]-65],seg_el) else: ANS=getvalues(int(y)-1,int(z)) LANS.append(ANS[3]) print("\n".join(map(str,LANS)))