import Control.Monad
g :: String -> [Int]->String
g s l=((drop ((l!!0)-1)).(take (l!!1))) s
f :: Int->String->Int
f n (s:l)=if null l then n else if s=='A'&&(head l)=='C' then f (n+1) l else f n l 
main=do
 [n,q]<-map read.words<$>getLine
 s<-getLine
 l<-map (map read.words)<$>replicateM q getLine
 putStr$unlines$map show$map (f 0)$map (g s) l