#include <bits/stdc++.h>
using namespace std;
int ct[3][3][3][200010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, i, j, k, l, r, x, ans, INF = 1LL << 60;
  string s;
  cin >> n >> m >> s;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      for (k = 0; k < 3; k++) {
        if ((i == j) || (j == k) || (k == i)) continue;
        ct[i][j][k][0] = 0;
        for (x = 1; x <= n; x++) {
          ct[i][j][k][x] = ct[i][j][k][x - 1];
          if ((x % 3 == 0) && (s[x - 1] - 'a' != i)) continue;
          if ((x % 3 == 1) && (s[x - 1] - 'a' != j)) continue;
          if ((x % 3 == 2) && (s[x - 1] - 'a' != k)) continue;
          ct[i][j][k][x]++;
        }
      }
    }
  }
  while (m--) {
    cin >> l >> r;
    if (l == r)
      ans = 0;
    else if (l + 1 == r) {
      if (s[l - 1] == s[r - 1])
        ans = 1;
      else
        ans = 0;
    } else {
      ans = INF;
      for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
          for (k = 0; k < 3; k++) {
            if ((i == j) || (j == k) || (k == i)) continue;
            x = ct[i][j][k][r] - ct[i][j][k][l - 1];
            ans = min(ans, r - l + 1 - x);
          }
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}

### Prompt

In Cpp, your task is to solve the following problem:

Let's call the string beautiful if it does not contain a substring of length at least 2, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, but the strings ab, abbbaa, cccb are not.

Let's define cost of a string as the minimum number of operations so that the string becomes beautiful, if in one operation it is allowed to change any character of the string to one of the first 3 letters of the Latin alphabet (in lowercase).

You are given a string s of length n, each character of the string is one of the first 3 letters of the Latin alphabet (in lowercase).

You have to answer m queries — calculate the cost of the substring of the string s from l_i-th to r_i-th position, inclusive.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the length of the string s and the number of queries.

The second line contains the string s, it consists of n characters, each character one of the first 3 Latin letters.

The following m lines contain two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — parameters of the i-th query.

Output

For each query, print a single integer — the cost of the substring of the string s from l_i-th to r_i-th position, inclusive.

Example

Input


5 4
baacb
1 3
1 5
4 5
2 3


Output


1
2
0
1

Note

Consider the queries of the example test.

  * in the first query, the substring is baa, which can be changed to bac in one operation; 
  * in the second query, the substring is baacb, which can be changed to cbacb in two operations; 
  * in the third query, the substring is cb, which can be left unchanged; 
  * in the fourth query, the substring is aa, which can be changed to ba in one operation. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ct[3][3][3][200010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, i, j, k, l, r, x, ans, INF = 1LL << 60;
  string s;
  cin >> n >> m >> s;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      for (k = 0; k < 3; k++) {
        if ((i == j) || (j == k) || (k == i)) continue;
        ct[i][j][k][0] = 0;
        for (x = 1; x <= n; x++) {
          ct[i][j][k][x] = ct[i][j][k][x - 1];
          if ((x % 3 == 0) && (s[x - 1] - 'a' != i)) continue;
          if ((x % 3 == 1) && (s[x - 1] - 'a' != j)) continue;
          if ((x % 3 == 2) && (s[x - 1] - 'a' != k)) continue;
          ct[i][j][k][x]++;
        }
      }
    }
  }
  while (m--) {
    cin >> l >> r;
    if (l == r)
      ans = 0;
    else if (l + 1 == r) {
      if (s[l - 1] == s[r - 1])
        ans = 1;
      else
        ans = 0;
    } else {
      ans = INF;
      for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
          for (k = 0; k < 3; k++) {
            if ((i == j) || (j == k) || (k == i)) continue;
            x = ct[i][j][k][r] - ct[i][j][k][l - 1];
            ans = min(ans, r - l + 1 - x);
          }
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}

```