const main = (s) => {
const src = s[1]
const qn = parseInt(s[0].split(" ")[1])
const questions = s.slice(2,2+qn)
const base = /AC/g
const list = []
for(var q of questions){
  var 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'))