#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323;
long long int n, k, m, tc, ans = 0, count = 0, mymax = -1e18, mymin = 1e18, x,
                           y;
string final_ans = "";
string s = "";
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (int i = 0; i < v.size(); i += 1) os << v[i] << " ";
  os << '\n';
  return os;
}
long long int fastexp(long long int base, long long int exp,
                      long long int mod) {
  long long int res = 1;
  while (exp > 0) {
    if (exp % 2) {
      res *= base;
      res %= mod;
    }
    exp /= 2;
    base *= base;
    base %= mod;
  }
  return res % mod;
}
long long int get_ans(vector<pair<int, int>> chords) {
  long long int ans = 0;
  for (int i = 0; i < chords.size(); i++) {
    for (int j = i + 1; j < chords.size(); j++) {
      long long int c11 = chords[i].first, c12 = chords[i].second;
      long long int c21 = chords[j].first, c22 = chords[j].second;
      if (c11 > c12) swap(c11, c12);
      if (c21 > c22) swap(c21, c22);
      vector<long long int> new_vec = {c11, c12, c21, c22};
      vector<long long int> one_vec = {c11, c21, c12, c22};
      vector<long long int> two_vec = {c21, c11, c22, c12};
      sort(new_vec.begin(), new_vec.end());
      if (new_vec == one_vec || new_vec == two_vec) ans++;
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int q;
  cin >> n >> q;
  cin >> s;
  map<char, map<int, int>> mymap;
  vector<map<char, map<int, int>>> running_map(n);
  for (int i = 0; i < s.length(); i += 1) {
    mymap[s[i]][i % 3]++;
    running_map[i] = mymap;
  }
  for (int i = 0; i < q; i += 1) {
    long long int l, r;
    cin >> l >> r;
    l--;
    r--;
    vector<char> chars = {'a', 'b', 'c'};
    map<char, map<int, int>> mymap2 = running_map[r];
    if (l != 0) {
      for (char x : chars) {
        for (int j = 0; j < 3; j++) {
          mymap2[x][j] -= running_map[l - 1][x][j];
        }
      }
    }
    ans = 1e18;
    vector<string> perms = {"abc", "acb", "bac", "bca", "cab", "cba"};
    for (string perm : perms) {
      long long int cnt = 0;
      for (int j = 0; j < 3; j++) {
        char mychar = perm[j];
        for (char otherChar : chars) {
          if (mychar != otherChar) cnt += mymap2[otherChar][j];
        }
      }
      ans = min(ans, cnt);
    }
    cout << ans << '\n';
  }
}
