//
//AtCoder Beginner Contest 122
//C
//https://atcoder.jp/contests/abc122/tasks/abc122_c
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;

    vector<pair<int,int>> lr(n);
    REP(i, q) {
        cin >> lr[i].first >> lr[i].second;
        lr[i].first--;
        lr[i].second--;
    }
    vector<int> sAC(n+1, 0);
    int acCnt=0;
    REP(i,n){
        if ((s[i]=='A') && (s[i+1]=='C')) acCnt++;
        sAC[i+1]=acCnt;
    }
    REP(i,q){
        int ans = sAC[lr[i].second] - sAC[lr[i].first];
        cout << ans << endl;
    }
    return 0;
}

#pragma GCC optimize(2)
#pragma GCC optimize("inline")
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#define mp make_pair
#define pb push_back
using namespace std;

typedef long long li;
template<class T>inline void read(T &x) {
  x = 0;
  T tmp = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') tmp = -1, c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + c - '0', c = getchar();
  x *= tmp;
}
template<class T>inline void Max(T &x, T y) {
  if (y > x) x = y;
}
template<class T>inline void Min(T &x, T y) {
  if (y < x) x = y;
}

const int N = 600;
int n, d1, d2, a[N][N], b[N][N];

const int dx[] = {1, 1, -1, -1};
const int dy[] = {1, -1, 1, -1};
inline bool out(int x, int y) {
  return x < 0 || y < 0 || x >= (n << 1) || y >= (n << 1);
}

vector<pair<int, int> > g, h;

struct node {
  int x, y, ty;
  node() {}
  node(int _x, int _y, int _ty) : x(_x), y(_y), ty(_ty) {}
};
queue<node> q;
void Fill_a(int Ax, int Ay) {
  q.push(node(Ax, Ay, 0));
  while (!q.empty()) {
    int x = q.front().x, y = q.front().y;
    int cur = q.front().ty;
    q.pop();
    if (a[x][y] != -1) continue;
    a[x][y] = cur;
    for (int i = 0; i < (int)g.size(); ++i) {
      int nowx = x + g[i].first, nowy = y + g[i].second;
      if (out(nowx, nowy) || a[nowx][nowy] != -1) continue;
      q.push(node(nowx, nowy, cur ^ 1));
    }
  }
}
void Fill_b(int Ax, int Ay) {
  q.push(node(Ax, Ay, 0));
  while (!q.empty()) {
    int x = q.front().x, y = q.front().y;
    int cur = q.front().ty;
    q.pop();
    if (b[x][y] != -1) continue;
    b[x][y] = cur;
    for (int i = 0; i < (int)h.size(); ++i) {
      int nowx = x + h[i].first, nowy = y + h[i].second;
      if (out(nowx, nowy) || b[nowx][nowy] != -1) continue;
      q.push(node(nowx, nowy, cur ^ 1));
    }
  }
}

int main(void) {
  read(n), read(d1), read(d2);
  for (int i = 0; i < 450; ++i)
    for (int j = 0; j < 450; ++j) {
      int now = i * i + j * j;
      if (now == d1) {
	for (int t = 0; t < 4; ++t)
	  g.pb(mp(i * dx[t], j * dy[t]));
      }
      if (now == d2) {
	for (int t = 0; t < 4; ++t)
	  h.pb(mp(i * dx[t], j * dy[t]));
      }
    }
  for (int i = 0; i < (n << 1); ++i)
    for (int j = 0; j < (n << 1); ++j)
      a[i][j] = b[i][j] = -1;
  for (int i = 0; i < (n << 1); ++i)
    for (int j = 0; j < (n << 1); ++j)
      if (a[i][j] == -1) Fill_a(i, j);
  for (int i = 0; i < (n << 1); ++i)
    for (int j = 0; j < (n << 1); ++j)
      if (b[i][j] == -1) Fill_b(i, j);
  
  for (int x = 0; x < 2; ++x)
    for (int y = 0; y < 2; ++y) {
      int cnt = 0;
      for (int i = 0; i < (n << 1); ++i)
	for (int j = 0; j < (n << 1); ++j)
	  cnt += (a[i][j] == x && b[i][j] == y);
      if (cnt >= n * n) {
	int m = n * n;
	for (int i = 0; i < (n << 1) && m; ++i)
	  for (int j = 0; j < (n << 1) && m; ++j)
	    if (a[i][j] == x && b[i][j] == y)
	      printf("%d %d\n", i, j), --m;
	return 0;
      }
    }
}
