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.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  
  public class CodeForces {
      static reader input = new reader();
      static PrintWriter output = new PrintWriter(System.out);
  
      public static void main(String[] args) throws IOException {
          /*
          BufferedReader bf = new BufferedReader(new FileReader("input.txt"));
          PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
          StringTokenizer stk= new StringTokenizer(bf.readLine());;
          int n=Integer.parseInt(stk.nextToken());
          */
          D();
          output.close();
      }
  
      public static void A(){
  
      }
  
      public static void B(){
  
      }
  
      public static void C(){
  
      }
  
      public static void D(){
          int n=input.nextInt(),m= input.nextInt();
          String s= input.next();
          int abc[]=new int[n];
          int acb[]=new int[n];
          int bac[]=new int[n];
          int bca[]=new int[n];
          int cab[]=new int[n];
          int cba[]=new int[n];
          if(s.charAt(n-1)=='a'){
              bac[n-1]=1;
              bca[n-1]=1;
              cab[n-1]=1;
              cba[n-1]=1;
          }else if(s.charAt(n-1)=='b'){
              abc[n-1]=1;
              acb[n-1]=1;
              cab[n-1]=1;
              cba[n-1]=1;
          }else{
              abc[n-1]=1;
              acb[n-1]=1;
              bac[n-1]=1;
              bca[n-1]=1;
          }
          for(int i=n-2;i>=0;i--){
              if(s.charAt(i)=='a'){
                  abc[i]=bca[i+1];
                  acb[i]=cba[i+1];
                  bac[i]=1+acb[i+1];
                  bca[i]=1+cab[i+1];
                  cab[i]=1+abc[i+1];
                  cba[i]=1+bac[i+1];
              }else if(s.charAt(i)=='b'){
                  abc[i]=1+bca[i+1];
                  acb[i]=1+cba[i+1];
                  bac[i]=acb[i+1];
                  bca[i]=cab[i+1];
                  cab[i]=1+abc[i+1];
                  cba[i]=1+bac[i+1];
              }else{
                  abc[i]=1+bca[i+1];
                  acb[i]=1+cba[i+1];
                  bac[i]=1+acb[i+1];
                  bca[i]=1+cab[i+1];
                  cab[i]=abc[i+1];
                  cba[i]=bac[i+1];
              }
          }
          for(int i=0;i<m;i++){
              int l=input.nextInt()-1,r=input.nextInt()-1;
              int a,b,c;
              if(r==n-1){
                  a=Math.min(abc[l],acb[l]);
                  b=Math.min(bac[l],bca[l]);
                  c=Math.min(cab[l],cba[l]);
              }else{
                  if((r-l)%3==2){
                      a=Math.min(abc[l]-abc[r+1],acb[l]-acb[r+1]);
                      b=Math.min(bac[l]-bac[r+1],bca[l]-bca[r+1]);
                      c=Math.min(cab[l]-cab[r+1],cba[l]-cba[r+1]);
                  }else if((r-l)%3==1){
                      a=Math.min(abc[l]-cab[r+1],acb[l]-bac[r+1]);
                      b=Math.min(bac[l]-cba[r+1],bca[l]-abc[r+1]);
                      c=Math.min(cab[l]-bca[r+1],cba[l]-acb[r+1]);
                  }else{
                      a=Math.min(abc[l]-bca[r+1],acb[l]-cba[r+1]);
                      b=Math.min(bac[l]-acb[r+1],bca[l]-cab[r+1]);
                      c=Math.min(cab[l]-abc[r+1],cba[l]-bac[r+1]);
                  }
              }
              output.println(Math.min(Math.min(a,b),c));
          }
      }
  
      public static void E(){
  
      }
  
      public static void F(){
  
      }
  
      public static long factorial(int a){
          long ans=1;
          for(int i=1;i<=a;i++){
              ans*=i;
          }
          return ans;
      }
      public static long LCM(long a,long b){
          return (a*b)/GCD(a,b);
      }
      public static long GCD(long a,long b){
          if(a==0)
              return b;
          else if(b==0)
              return a;
          else
              return GCD(b%a,a);
      }
  
      public static boolean isPrime(long num){
          if(num==1)
              return false;
          else if(num==2||num==3)
              return true;
          else if(num%2==0||num%3==0)
              return false;
          else{
              for(long i=5;i*i<=num;i+=6){
                  if(num%i==0||num%(i+2)==0)
                      return false;
              }
          }
          return true;
      }
  
      public static ArrayList<Integer> SieveofEratothenis(){
          ArrayList<Integer>ans=new ArrayList<>();
          boolean visited[]=new boolean[1000000];
          for(int i=2;i<1000000;i++){
              if(!visited[i]){
                  ans.add(i);
                  for(long j=(long)i*i;j<1000000;j+=i){
                      visited[(int)j]=true;
                  }
              }
          }
          return ans;
      }
  
      public static void mergesort(long arr[],int start,int end){//start and end must be indexes
          if(start<end) {
              int mid=(start+end)/2;
              mergesort(arr,start,mid);
              mergesort(arr, mid+1, end);
              merge(arr, start,mid,end);
          }
      }
      public static void merge(long arr[],int start,int mid,int end){
          int lsize=mid-start+1,rsize=end-mid;
          long l[]=new long[lsize],r[]=new long[rsize];
          for(int i=start;i<=mid;i++){
              l[i-start]=arr[i];
          }
          for(int i=mid+1;i<=end;i++){
              r[i-mid-1]=arr[i];
          }
          int i=0,j=0,k=start;
          while(i<lsize&&j<rsize){
              if(l[i]<=r[j]){
                  arr[k++]=l[i++];
              }else{
                  arr[k++]=r[j++];
              }
          }
          while(i<lsize)
              arr[k++]=l[i++];
          while(j<rsize)
              arr[k++]=r[j++];
      }
  }
  
  class Value{
      int ans;
      Value(int ans)
      {
          this.ans=ans;
      }
  }
  
  class Triple{
      int x,y,z;
      Triple(int x,int y,int z){
          this.x=x;
          this.y=y;
          this.z=z;
      }
  }
  
  class Pair{
      int x, y;
      Pair(int x,int y){
          this.x=x;
          this.y=y;
      }
  }
  
  class Op{
      int op,count;
      char dir;
      public Op(int op){
          this.op=op;
      }
  }
  
  class reader {
      BufferedReader br;
      StringTokenizer st;
  
      public reader() {
          br = new BufferedReader(new
                  InputStreamReader(System.in));
      }
  
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
  
      int nextInt() {
          return Integer.parseInt(next());
      }
  
      long nextLong() {
          return Long.parseLong(next());
      }
  
      double nextDouble() {
          return Double.parseDouble(next());
      }
  
      String nextLine() {
          String str = "";
          try {
              str = br.readLine();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return str;
      }
  
      public int[] nextIntArray(int arraySize) {
          int array[] = new int[arraySize];
          for (int i = 0; i < arraySize; i++) {
              array[i] = nextInt();
          }
          return array;
      }
  
      public long[] nextLongArray(int arraySize) {
          long array[] = new long[arraySize];
          for (int i = 0; i < arraySize; i++) {
              array[i] = nextLong();
          }
          return array;
      }
  }