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

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