const main = (s) => {
const src = s[1]
const length = s[0].split("")[0]
const questionsNum = 2+s[0].split(" ")[1]
const questions = s.slice(2,questionsNum>length?length:questionsNum)
const base = /AC/g
const list  =[]
questions.forEach(q=>{
  	const result = src.substring(q.split(" ")[0]-1,q.split(" ")[1]).match(base)||[]
    list.push(result.length)
})
console.log(list.join('\n'))
}

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