#include <bits/stdc++.h>
using namespace std;
long long arr[200000];
struct product {
  long long a, b;
};
bool compare(product m, product n) { return m.b < n.b; }
long long fast_mod(long long a, long long b, long long mod) {
  long long r = 1;
  a %= mod;
  while (b) {
    if (b & 1) r = (r * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return r;
}
bool isSushu(int x) {
  if (x == 1) return false;
  for (int i = 2; i <= ceil(sqrt(x)) && i < x; i++)
    if (x % i == 0) return false;
  return true;
}
const long long mod = 31607;
int main() {
  int t = 1;
  while (t-- > 0) {
    int n, m, sum[6][300000];
    string s[6];
    s[0] = "abc";
    s[1] = "acb";
    s[2] = "bac";
    s[3] = "bca";
    s[4] = "cab";
    s[5] = "cba";
    string ss;
    cin >> n >> m >> ss;
    for (int i = 0; i < n; i++) {
      char ch = ss[i];
      for (int j = 0; j < 6; j++)
        sum[j][i] = (i > 0 ? sum[j][i - 1] : 0) + (ch == s[j][i % 3] ? 0 : 1);
    }
    for (int i = 0; i < m; i++) {
      int l, r, ans;
      cin >> l >> r;
      l--;
      r--;
      ans = r - l + 1;
      for (int j = 0; j < 6; j++)
        ans = min(ans, (sum[j][r] - (l > 0 ? sum[j][l - 1] : 0)));
      cout << ans << endl;
    }
  }
  return 0;
}
