description: 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. 
solution: import java.net.Inet4Address;
  import java.util.*;
  import java.io.*;
  
  public class Div735 {
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////                                                                                                               /////////
  ////////                                                                                                               /////////
  ////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////
  ////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMMMM      MMMMMM      OOO      OOO        SSSS   SSS     EEEEEEEEEEEEE  /////////
  ////////   HHHH        HHHH  EEEEE           MMMM MMM  MMM MMMM    OOO          OOO    SSSS       SSS   EEEEE          /////////
  ////////   HHHH        HHHH  EEEEE           MMMM  MMMMMM  MMMM   OOO            OOO   SSSS             EEEEE          /////////
  ////////   HHHH        HHHH  EEEEE           MMMM          MMMM  OOO              OOO   SSSSSSS         EEEEE          /////////
  ////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO      SSSSSS       EEEEEEEEEEE    /////////
  ////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO         SSSSSSS   EEEEEEEEEEE    /////////
  ////////   HHHH        HHHH  EEEEE           MMMM          MMMM   OOO            OOO              SSSS  EEEEE          /////////
  ////////   HHHH        HHHH  EEEEE           MMMM          MMMM    OOO          OOO     SSS       SSSS  EEEEE          /////////
  ////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM      OOO      OOO        SSS    SSSS    EEEEEEEEEEEEE  /////////
  ////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////
  ////////                                                                                                               /////////
  ////////                                                                                                               /////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      static int getcount(int v, int mod) {
          if (v < 0)
              return 0;
          int ans = v / 3;
          if (v % 3 >= mod)
              ans++;
          return ans;
      }
  
      public static void main(String[] args) throws IOException {
          Scanner sc = new Scanner(System.in);
          PrintWriter pw = new PrintWriter(System.out);
          int t = 1;
          while (t-- > 0) {
              int n = sc.nextInt();
              int m = sc.nextInt();
  
              char[] s = sc.next().toCharArray();
              int[][][] count = new int[3][3][n];
  
              for (int i = 0; i < n; i++) {
                  count[s[i] - 'a'][i % 3][i]++;
                  if (i > 0)
                      for (int mod = 0; mod < 3; mod++) {
                          for (int chr = 0; chr < 3; chr++) {
                              count[chr][mod][i] += count[chr][mod][i - 1];
                          }
                      }
              }
  
              while (m-- > 0) {
                  int l = sc.nextInt() - 1;
                  int r = sc.nextInt() - 1;
  
                  int ans = r - l + 1;
                  for (int c = 0; c < 3; c++) {
                      for (int c2 = 0; c2 < 3; c2++) {
                          if (c == c2)
                              continue;
                          for (int c3 = 0; c3 < 3; c3++) {
                              if (c == c3 || c3 == c2)
                                  continue;
  
                              int curr = r - l + 1;
                              curr -= (count[c][0][r] - (l == 0 ? 0 : count[c][0][l - 1]));
                              curr -= (count[c2][1][r] - (l == 0 ? 0 : count[c2][1][l - 1]));
                              curr -= (count[c3][2][r] - (l == 0 ? 0 : count[c3][2][l - 1]));
                              ans = Math.min(ans, curr);
                          }
                      }
                  }
                  pw.println(ans);
              }
          }
          pw.flush();
      }
  
      static class Scanner {
          StringTokenizer st;
          BufferedReader br;
  
          public Scanner(FileReader r) {
              br = new BufferedReader(r);
          }
  
          public Scanner(InputStream s) {
              br = new BufferedReader(new InputStreamReader(s));
          }
  
          public String next() throws IOException {
              while (st == null || !st.hasMoreTokens())
                  st = new StringTokenizer(br.readLine());
              return st.nextToken();
          }
  
          public int[] nextIntArr(int n) throws IOException {
              int[] a = new int[n];
              for (int i = 0; i < n; i++) {
                  a[i] = nextInt();
              }
              return a;
          }
  
          public int nextInt() throws IOException {
              return Integer.parseInt(next());
          }
  
          public long nextLong() throws IOException {
              return Long.parseLong(next());
          }
  
          public String nextLine() throws IOException {
              return br.readLine();
          }
  
          public double nextDouble() throws IOException {
              String x = next();
              StringBuilder sb = new StringBuilder("0");
              double res = 0, f = 1;
              boolean dec = false, neg = false;
              int start = 0;
              if (x.charAt(0) == '-') {
                  neg = true;
                  start++;
              }
              for (int i = start; i < x.length(); i++)
                  if (x.charAt(i) == '.') {
                      res = Long.parseLong(sb.toString());
                      sb = new StringBuilder("0");
                      dec = true;
                  } else {
                      sb.append(x.charAt(i));
                      if (dec)
                          f *= 10;
                  }
              res += Long.parseLong(sb.toString()) / f;
              return res * (neg ? -1 : 1);
          }
  
          public boolean ready() throws IOException {
              return br.ready();
          }
      }
  
  }