#include <bits/stdc++.h>
using namespace std;
int N, Q;
string S;
int l[100000];
int r[100000];
int t[100000];
int main() {
  cin >> N >> Q;
  cin >> S;
  for (int i = 0; i < Q; ++i) cin >> l[i] >> r[i];
  if ((S[0] == 'A') && (S[1] == 'C')) {
    t[0] = 1;
  } else {
    t[0] = 0;
  }
  for (int i = 1; i < N; ++i) {
    if ((S[i] == 'A') && (S[i + 1] == 'C')) {
      t[i] = t[i - 1] + 1;
    } else {
      t[i] = t[i - 1];
    }
  }
  for (int i = 0; i < Q; ++i) {
    cout << t[r[i] - 2] - t[l[i] - 2] << endl;
  }
}
