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.util.*;
  import java.math.*;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.StringTokenizer;
  
  
  public class b{ 
  
       static FastScanner sc;
       static TreeSet<Integer> ans;
       static long[] arr,dp;
       static char[][] board;
       static long mul,mul1;
       static int[] spf;
       static char[] ch;
       static int n,q,m;
       static long k,x;
       static StringBuilder sb;
       static long a,sum;
       static Map<Integer,List<Integer>> map;
      static Map<Long,List<Integer>> map2;
      static Map<Long,List<Integer>> map3;
      static Map<Integer,Integer> shortest;
      static Map<Integer,List<Integer>> map1;
      static List<Integer> list,list1;
      static int[] count;
  
      // static class Node{
      //     long dist;
      //     Set<Integer> set;
      //     Node(){
      //         this.set = new HashSet<>();
      //     }
      //     Node(int f){
      //         this.dist = f;
      //         this.set = new HashSet<>();
      //     }
      // }
  
      // public static class Lca {
  
      //     int[] depth;
      //     int[] dfs_order;
      //     int cnt;
      //     int[] first;
      //     int[] minPos;
      //     int n;
  
      //     void dfs(List<Integer>[] tree, int u, int d) {
      //         depth[u] = d;
      //         dfs_order[cnt++] = u;
      //         for (int v : tree[u])
      //             if (depth[v] == -1) {
      //                 dfs(tree, v, d + 1);
      //                 dfs_order[cnt++] = u;
      //             }
      //     }
  
      //     void buildTree(int node, int left, int right) {
      //         if (left == right) {
      //             minPos[node] = dfs_order[left];
      //             return;
      //         }
      //         int mid = (left + right) >> 1;
      //         buildTree(2 * node + 1, left, mid);
      //         buildTree(2 * node + 2, mid + 1, right);
      //         minPos[node] = depth[minPos[2 * node + 1]] < depth[minPos[2 * node + 2]] ? minPos[2 * node + 1] : minPos[2 * node + 2];
      //     }
  
      //     public Lca(List<Integer>[] tree, int root) {
      //         int nodes = tree.length;
      //         depth = new int[nodes];
      //         Arrays.fill(depth, -1);
  
      //         n = 2 * nodes - 1;
      //         dfs_order = new int[n];
      //         cnt = 0;
      //         dfs(tree, root, 0);
  
      //         minPos = new int[4 * n];
      //         buildTree(0, 0, n - 1);
  
      //         first = new int[nodes];
      //         Arrays.fill(first, -1);
      //         for (int i = 0; i < dfs_order.length; i++)
      //             if (first[dfs_order[i]] == -1)
      //                 first[dfs_order[i]] = i;
      //     }
  
      //     public int lca(int a, int b) {
      //         return minPos(Math.min(first[a], first[b]), Math.max(first[a], first[b]), 0, 0, n - 1);
      //     }
  
      //     int minPos(int a, int b, int node, int left, int right) {
      //         if (a == left && right == b)
      //             return minPos[node];
      //         int mid = (left + right) >> 1;
      //         if (a <= mid && b > mid) {
      //             int p1 = minPos(a, Math.min(b, mid), 2 * node + 1, left, mid);
      //             int p2 = minPos(Math.max(a, mid + 1), b, 2 * node + 2, mid + 1, right);
      //             return depth[p1] < depth[p2] ? p1 : p2;
      //         } else if (a <= mid) {
      //             return minPos(a, Math.min(b, mid), 2 * node + 1, left, mid);
      //         } else if (b > mid) {
      //             return minPos(Math.max(a, mid + 1), b, 2 * node + 2, mid + 1, right);
      //         } else {
      //             throw new RuntimeException();
      //         }
      //     }
      // }
  
      // private static long dfs(int v, int parent,long ht) {
  
      //     List<Integer> list = map.get(v);
      //     hyt[v] = ht;
  
      //     if(list.size() == 1){
      //         if(!map3.containsKey(ht))
      //             map3.put(ht,new ArrayList<>());
  
      //         map3.get(ht).add(v);
      //         return ht;
  
      //     }
  
      //     long maxl = -1;
      //     for(Integer i : list){
      //         if(i == parent)
      //             continue;
      //         maxl = Math.max(maxl,dfs(i,v,ht+1));
      //     }
  
      //     return maxl;
  
      // }
  
      public static void solve(){
  
           char[] ch1 = new char[n];
          char[] ch2 = new char[n];
          char[] ch3 = new char[n];
          char[] ch4 = new char[n];
          char[] ch5 = new char[n];
          char[] ch6 = new char[n];
  
          char[][] c1 = new char[6][n];
  
          for(int i = 0 ; i < n ; i++){
              if(i%3 == 0)
                  ch1[i] = 'a';
              else if(i%3 == 1)
                  ch1[i] = 'b';
              else
                  ch1[i] = 'c';
              c1[0][i] = ch1[i];
          }
  
          for(int i = 0 ; i < n ; i++){
              if(i%3 == 0)
                  ch2[i] = 'a';
              else if(i%3 == 1)
                  ch2[i] = 'c';
              else
                  ch2[i] = 'b';
              c1[1][i] = ch2[i];
          }
  
          for(int i = 0 ; i < n ; i++){
              if(i%3 == 0)
                  ch6[i] = 'b';
              else if(i%3 == 1)
                  ch6[i] = 'a';
              else
                  ch6[i] = 'c';
              c1[5][i] = ch6[i];
          }
  
          for(int i = 0 ; i < n ; i++){
              if(i%3 == 0)
                  ch3[i] = 'b';
              else if(i%3 == 1)
                  ch3[i] = 'c';
              else
                  ch3[i] = 'a';
              c1[2][i] = ch3[i];
          }
  
          for(int i = 0 ; i < n ; i++){
              if(i%3 == 0)
                  ch4[i] = 'c';
              else if(i%3 == 1)
                  ch4[i] = 'a';
              else
                  ch4[i] = 'b';
              c1[3][i] = ch4[i];
          }
  
          for(int i = 0 ; i < n ; i++){
              if(i%3 == 0)
                  ch5[i] = 'c';
              else if(i%3 == 1)
                  ch5[i] = 'b';
              else
                  ch5[i] = 'a';
              c1[4][i] = ch5[i];
          }
  
  //        char[][] c1 = new char[6][n];
  //        for(int j = 0 ; j < n ; j++){
  //            c1[0][j] = ch1[i];
  //        }
  
          int[][] dp = new int[6][n];
  
          for(int i = 0 ; i < n ; i++){
              for(int j = 0 ; j < 6 ; j++){
                  if(c1[j][i] != ch[i]) {
                      if(i-1 >= 0)
                          dp[j][i] = 1 + dp[j][i-1];
                      else
                          dp[j][i] = 1;
                  }
                  else{
                      if(i-1 >= 0)
                          dp[j][i] = dp[j][i-1];
                  }
              }
          }
          sb = new StringBuilder();
          for(int i = 0 ; i < q ; i++){
  
              int l = sc.nextInt()-1;
              int r = sc.nextInt()-1;
              int curr = Integer.MAX_VALUE;
  
              for(int j = 0 ; j < 6 ; j++){
                  if(l == 0)
                      curr = Math.min(curr,dp[j][r]);
                  else
                      curr = Math.min(curr,dp[j][r] - dp[j][l-1]);
              }
  
              sb.append(curr).append("\n");
  
          }
  
          System.out.println(sb);
  
      }
          
       public static void main(String[] args) {
  
              sc = new FastScanner();
              // Scanner sc = new Scanner(System.in);
              // SpecialSieve(5000000+5);
              // int t = sc.nextInt();
              // sb = new StringBuilder();
              int t = 1;
              while(t > 0){
  
                  // a = sc.nextLong();
                  n = sc.nextInt();
                  // k = sc.nextLong();
                  // x = sc.nextLong();
                  // m = sc.nextInt();
                  // for(int i = 1 ; i <= 15 ; i++){
                  //     m = i;
                  //     solve();
                  // // }
                  // board = new char[3][3];
                  // for(int i = 0 ; i < 3 ; i++){
                  //     String s = sc.next();
                  //     for(int j = 0 ; j < 3 ; j++){
                  //         board[i][j] = s.charAt(j);
                  //     }
                  // }
                  // x = sc.nextInt();
                  // ch = sc.next().toCharArray();
                  q = sc.nextInt();
                  ch = sc.next().toCharArray();
                  // arr = new long[n];
                  // for(int i = 0 ; i < n ; i++)
                  //     arr[i] = sc.nextLong();
                  solve();
                  t -= 1;
              }
              // System.out.print(sb);
  
       }
  
      // Use this instead of Arrays.sort() on an array of ints. Arrays.sort() is n^2
      // worst case since it uses a version of quicksort. Although this would never
      // actually show up in the real world, in codeforces, people can hack, so
      // this is needed.
      static void ruffleSort(long[] a) {
          //ruffle
          int n=a.length;
          Random r=new Random();
          for (int i=0; i<a.length; i++) {
              int oi=r.nextInt(n);long temp=a[i];
              a[i]=a[oi];
              a[oi]=temp;
          }
          
          //then sort
          Arrays.sort(a);
      }
      public static long gcd(long a, long b)
      {
        if (b == 0)
          return a;
  
        return gcd(b, a % b); 
        
      }
       public static int log(double n,double base){
  
          if(n == 0 || n == 1)
              return 0;
  
          if(n == base)
              return 1;
  
          double num = Math.log(n);
          double den = Math.log(base);
  
          if(den == 0)
              return 0;
  
          return (int)(num/den);
      }
      public static long mod(long x, long mod)
  {
      long result = x % mod;
      if (result < 0)
      {
          result += mod;
      }
      return result;
  }
      
      // Use this to input code since it is faster than a Scanner
      static class FastScanner {
          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
          StringTokenizer st=new StringTokenizer("");
          String next() {
              while (!st.hasMoreTokens())
                  try {
                      st=new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              return st.nextToken();
          }
          
          int nextInt() {
              return Integer.parseInt(next());
          }
          int[] readArray(int n) {
              int[] a=new int[n];
              for (int i=0; i<n; i++) a[i]=nextInt();
              return a;
          }
          long nextLong() {
              return Long.parseLong(next());
          }
      }
  }
  