#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> AC(N+1,0);
  for (int i = 0; i < N; i++) {
    AC[i+1] = AC[i];
    if (S[i] == 'A' && S[i+1] == 'C') AC[i+1]++;
  }
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << AC[r-1] - AC[l-1] << endl;
  }
}
