import std.stdio, std.string, std.conv, std.array;
import std.algorithm, std.regex, std.range;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
  auto n = read.to!long, q = read.to!long;
  auto xs = readln.chomp.split("AC").map!"a.length".array;
  auto ps = xs.length.iota.map!(i => new long[](xs[i] + 2).map!(_ => i).array).join();
  foreach(_; q.iota){
    auto l = read.to!long, r = read.to!long;
    (ps[r] - ps[l]).writeln;
  }
}