#include <iostream>
#include <cmath>
#include <cassert>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <type_traits>
#include <fstream>
//#include <bits/stdc++.h>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// ll x = maximum(5, 4, 3, 2, 1);
// ll x = maximum(5, 4, 3, 2);
// ll y = minimum(5, 4, 3, 2, 1);
// ll y = minimum(5, 4, 3);
template<typename T> T maximum(T head, T tail) { return std::max(head, tail); }
template<typename Head, typename... Tail> Head maximum(Head head, Tail... tail) {
  return std::max(head, maximum(tail...));
}

template<typename T> T minimum(T head, T tail) { return std::min(head, tail); }
template<typename Head, typename... Tail> Head minimum(Head head, Tail... tail) {
  return std::min(head, minimum(tail...));
}

// print(x, y, z);
// printVec(va.begin(), va.end());
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << *it << " ";
    if ((it - begin) % 20 == 19 || it == end - 1) { std::cout << std::endl; }
  }
}
template<typename Iterator> void printVecPair(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << it->first << " " << it->second << " ";
    if ((it - begin) % 10 == 9 || it == end - 1) std::cout << std::endl;
  }
}

template<typename T> T bitnum(T x)
{
  T cnt = 1;
  T ret = 0;
  while (x > 0) {
    ret += (x % 2) * cnt;
    x /= 2;
    cnt *= 10;
  }
  return ret;
}

template<typename T> T lminimum(const std::vector< T >& v) {return *std::min_element(v.begin(), v.end());}
template<typename T> T lmaximum(const std::vector< T >& v) {return *std::max_element(v.begin(), v.end());}
template<typename T> void lunique(std::vector< T >& v) {v.erase(std::unique(v.begin(), v.end()), v.end());}
template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}
template<typename T> void lgreatersort(std::vector< T >& v) {std::sort(v.begin(), v.end(), std::greater<>());}
template<typename T> bool lnext_permutation(std::vector< T >& v) {return std::next_permutation(v.begin(), v.end());}

int main(int argc, char* argv[])
{
  ll N, Q;
  std::cin >> N >> Q;
  std::string S;
  std::cin >> S;
  std::vector< ll > vl(Q, 0LL);
  std::vector< ll > vr(Q, 0LL);
  for (ll i = 0; i < Q; i++) {
    std::cin >> vl[i] >> vr[i];
    vl[i]--; vr[i]--;
  }

  std::vector< ll > vcount(N, 0LL);
  bool is_on = S[0] == 'A' ? true : false;
  for (ll i = 1; i < N; i++) {
    char c = S[i];
    vcount[i] = vcount[i-1];
    if (c == 'A') {
      is_on = true;
      continue;
    }
    if (is_on and c == 'C') {
      vcount[i]++;
    }
    is_on = false;
  }
  //printVec(vcount.begin(), vcount.end());
  for (ll i = 0; i < Q; i++) {
    std::cout << vcount[vr[i]] - vcount[vl[i]] << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3456