const main = (s) => {
s = s.split('\n')
const length = s[0].split("")[0]
const questionNum = s[0].split(" ")[1]
const src = s[1]
var start = 0
var end = 0
const base = /AC/gm
const questions = s.slice(2,2+questionNum)
questions.forEach(q=>{
	start = q.split(" ")[0]
  	end = q.split(" ")[1]
  	const result = src.substring(start-1,end).match(base)||[]
    console.log(result.length)
})
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())