#include <bits/stdc++.h>
using namespace std;
const long long maxm = 2e6 + 5;
long long sum[10][maxm];
char s[maxm];
long long n, m;
void solve() {
  cin >> n >> m;
  cin >> (s + 1);
  long long num = 0;
  for (auto i : {'a', 'b', 'c'}) {
    for (auto j : {'a', 'b', 'c'}) {
      for (auto k : {'a', 'b', 'c'}) {
        if (i != j && i != k && j != k) {
          num++;
          for (long long x = 1; x <= n; x++) {
            sum[num][x] = sum[num][x - 1];
            if (x % 3 == 1)
              sum[num][x] += (s[x] != i);
            else if (x % 3 == 2)
              sum[num][x] += (s[x] != j);
            else if (x % 3 == 0)
              sum[num][x] += (s[x] != k);
          }
        }
      }
    }
  }
  while (m--) {
    long long l, r;
    cin >> l >> r;
    long long ans = 1e9;
    for (long long i = 1; i <= num; i++) {
      ans = min(ans, sum[i][r] - sum[i][l - 1]);
    }
    cout << ans << endl;
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
