import sys input = sys.stdin.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)] 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 #print(x,y) 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 for i in range(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]=x i>>=1 # 子ノードへ while i!=0: SEG[i]=seg_function(SEG[i*2],SEG[i*2+1]) 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() AX=[] for i in range(4): X=[1]*10 for j in range(i+1): for k in range(i,4): X[LIST[j][k]]=0 #print(X) AX.append(X) for i in range(len(S)): update(i,AX[ord(S[i])-65],seg_el) LANS=[] for tests in range(Q): x,y,z=input().split() if int(x)==1: y=int(y)-1 update(y,AX[ord(z)-65],seg_el) else: ANS=getvalues(int(y)-1,int(z)) LANS.append(ANS[3]) print("\n".join(map(str,LANS)))