#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 1e5 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long LINF = 1e18;
void solve() {
  long long n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<vector<long long>> costs(6, vector<long long>(n));
  vector<string> strs{"abc", "acb", "bac", "bca", "cba", "cab"};
  for (long long i{}; i < 6; ++i) {
    long long t{};
    for (long long j{}; j < n; ++j) {
      if (s[j] != strs[i][(j % 3)]) t++;
      costs[i][j + 1] = t;
    }
  }
  for (long long i{}; i < m; ++i) {
    long long a, b;
    cin >> a >> b;
    long long small = costs[0][b] - costs[0][a - 1];
    for (long long i{1}; i < 6; ++i) {
      small = min(small, costs[i][b] - costs[i][a - 1]);
    }
    cout << small << '\n';
  }
}
long long main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
