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.io.*;
  import java.util.*;
  
  public class codeforce {
  
      static class Reader {
          final private int BUFFER_SIZE = 1 << 16;
          private DataInputStream din;
          private byte[] buffer;
          private int bufferPointer, bytesRead;
  
          public Reader()
          {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public Reader(String file_name) throws IOException
          {
              din = new DataInputStream(
                      new FileInputStream(file_name));
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public String readLine() throws IOException
          {
              byte[] buf = new byte[64]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n') {
                      if (cnt != 0) {
                          break;
                      }
                      else {
                          continue;
                      }
                  }
                  buf[cnt++] = (byte)c;
              }
              return new String(buf, 0, cnt);
          }
  
          public int nextInt() throws IOException
          {
              int ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          public long nextLong() throws IOException
          {
              long ret = 0;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (neg)
                  return -ret;
              return ret;
          }
  
          public double nextDouble() throws IOException
          {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
  
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (c == '.') {
                  while ((c = read()) >= '0' && c <= '9') {
                      ret += (c - '0') / (div *= 10);
                  }
              }
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          private void fillBuffer() throws IOException
          {
              bytesRead = din.read(buffer, bufferPointer = 0,
                      BUFFER_SIZE);
              if (bytesRead == -1)
                  buffer[0] = -1;
          }
  
          private byte read() throws IOException
          {
              if (bufferPointer == bytesRead)
                  fillBuffer();
              return buffer[bufferPointer++];
          }
  
          public void close() throws IOException
          {
              if (din == null)
                  return;
              din.close();
          }
      }
      static int mod = (int) (1e9 + 7);
  
      public static class pair implements Comparator<pair> {
          int x;
          int y;
  
          public pair() {
  
          }
  
          public pair(int x, int y) {
              this.x = x;
              this.y = y;
  
          }
  
          @Override
          public int compare(pair o1, pair o2) {
              return o1.y - o2.y;
          }
      }
      public static long modularpow(long a,long b){
          long res=1;
          if(b==0)
              return res;
          else
          {
              while(b>0){
                  if(b%2==1){
                      res*=a;
                      res%=mod;
  
                  }
                  a=a*a;
                  a%=mod;
                  b/=2;
              }
              return res%mod;
          }
      }
      public static int gcd(int a,int b){
          if(b==0)
              return a;
          else
              return gcd(b,a%b);
      }
      public static String binary(int a){
          String s1="";
          while(a>0){
              s1=a%2+s1;
              a/=2;
          }
          return s1;
      }
      public static int Lower_Bound(long a[],int l,int r,long k){
  
  
          while(r-l>1){
              int mid=l+(r-l)/2;
              if(a[mid]<=k) l=mid;
              else
                  r=mid;
  
          }
          return l;
      }
      public static int Upper_Bound(int a[],int l,int r,int k){
  
          while(r-l>1){
              int mid=(l+r)/2;
              if(a[mid]<=k)
                  l=mid;
              else
                  r=mid;
          }
          return l+1;
      }
      public static void main(String arg[]) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=1;
        StringBuilder sb=new StringBuilder();
        while(t-->0){
              String s[]=br.readLine().split(" ");
            int n=Integer.parseInt(s[0]);
            int m=Integer.parseInt(s[1]);
            String s1=br.readLine();
            List<String> ar= Arrays.asList("abc","bca","cab","acb","bac","cba");
            ArrayList<ArrayList<Integer>>dr=new ArrayList<ArrayList<Integer>>(6);
            for(int i=0;i<6;i++)
                dr.add(new ArrayList<Integer>());
            get(s1,dr,ar);
            for(int i=0;i<m;i++){
                s=br.readLine().split(" ");
                int l=Integer.parseInt(s[0]);
                int r=Integer.parseInt(s[1]);
                int ans=Integer.MAX_VALUE;
                for(int j=0;j<6;j++)
                    ans=Math.min(ans,dr.get(j).get(r)-dr.get(j).get(l-1));
                sb.append(ans+"\n");
            }
  
        }
  System.out.println(sb);
      }
  public static  void get(String s, ArrayList<ArrayList<Integer>>dr, List<String> ar){
          for(int i=0;i<ar.size();i++){
              String s1=ar.get(i);
              dr.get(i).add(0);
              int ind=0;
              for(int j=0;j<s.length();j++){
                  if(s.charAt(j)!=s1.charAt(j%3))
                  {
                      ind++;
                  }
                  dr.get(i).add(ind);
              }
          }
  }
  }
  