'use strict'

function main(input) {
  const obj = { A: true, C: true }
  input = input.split('\n').map(v => v.split(' '))
  const n = ~~input[0][0]
  const qn = ~~input[0][1]
  let str = input[1][0].split('')
  let Q = input.slice(2, -1)
  Q = Q.map(v => v.map(v2 => ~~v2))

  let count = [0]
  let tmp = 0
  for (let i = 1; i < n; i++) {
    if (str[i - 1] == 'A' && str[i] == 'C') {
      tmp += 1
    }
    count[i] = tmp
  }

  let ans = ''
  let xxx = 0
  for (let i = 0; i < qn; i++) {
    let l = Q[i][0]
    let r = Q[i][1]
    xxx = count[r - 1] - count[l - 1]
    ans += xxx + '\n'
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))