input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
line = lines.shift().split(' ')
N = line[0] * 1
Q = line[1] * 1 
S = lines.shift()
a = [0]
cnt = 0
for (i=0; i<S.length-1; i++) {
    if (S[i] == 'A' && S[i+1] == 'C') {
        cnt++
    }
    a[i+1] = cnt
}
for (i=0; i<Q; i++) {
    line = lines[i].split(' ')
    l = line[0] * 1
    r = line[1] * 1
    console.log(a[r-1] - a[l-1])
}
