"use strict";
const main = (input) => {
    const inputs = input.trim().split("\n");
    const S = inputs[1];
    const map = [];
    let cnt = 0;
    for(let i=0;i<S.length;i++){
      if(S[i]=='C' && S[i-1]=='A') cnt++;
      map[i+1]=cnt;
    }
    for(let i=2;i<inputs.length;i++){
      let l = Number(inputs[i].split(" ")[0]);
      let r = Number(inputs[i].split(" ")[1]);
      console.log(map[r]-map[l]);
    }
  }
  
  main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));
  