'use strict'
function main(input) {
  input = input.trim().split('\n')
  const NQ = input.shift().split(' ').map(v => Number(v))
  const S = input.shift()
  const ans = []
  const count = [0]

  for (let i = 0; i < NQ[0] - 1; i++) {
    let newCount = i ? count[i-1] : 0
    if (S[i]==='A'&&S[i+1]==='C') newCount++
    count.push(newCount)
  }

  input.forEach(val => {
    const LR = val.split(' ').map(v => Number(v))
    ans.push(count[LR[1]-1] - count[LR[0]-1] + 1)
  })

  console.log(ans.join('\n'));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
