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 javax.print.attribute.IntegerSyntax;
  
  import java.io.*;
  import java.lang.reflect.Array;
  import java.math.BigInteger;
  import java.util.*;
  public class Main {
  
  	static boolean[] primecheck = new boolean[1000002];
  	static ArrayList<Long> lucky = new ArrayList<>();
  
  	public static void main(String[] args) throws IOException {
  		OutputStream outputStream = System.out;
  		FastReader in = new FastReader();
  		PrintWriter out = new PrintWriter(outputStream);
  		PROBLEM solver = new PROBLEM();
  
  			solver.solve(in, out);
  
  		  out.close();
  	}
  
  	public static void luckIsCalling(long n){
  
  		long a = n*10 + 4;
  		long b = n*10 + 7;
  
  		lucky.add(a);
  		lucky.add(b);
  
  		if(a<=4444444444L) luckIsCalling(a);
  		if(b<=4444444444L) luckIsCalling(b);
  	}
  
  	static class PROBLEM {
  		public void solve(FastReader in, PrintWriter out) {
  			 int n = in.nextInt();
  			 int m = in.nextInt();
  			 String s = in.nextLine();
              int l ,r;
              String arr[] = new String[6];
              arr[0]="abc";
              arr[1]="acb";
              arr[2]="cab";
              arr[3]="cba";
              arr[4]="bac";
              arr[5]="bca";
              int mat[][] = new int[6][n+1];
              for(int i=0;i<6;i++)
              {
                  int idx=0;
                  for(int j=0;j<n;j++)
                  {
                      mat[i][j+1] = mat[i][j];
                      if(arr[i].charAt(idx)!=s.charAt(j))
                      {
                          mat[i][j+1]+=1;
                      }
                      idx++;
                      if(idx>=3)
                      {
                          idx=0;
                      }
                  }
              }
              int ans;
               StringBuilder fans = new StringBuilder("");
  			 while(m-->0)
               {
                   l = in.nextInt();
                   r = in.nextInt();
                   ans = Integer.MAX_VALUE;
                   for(int i=0;i<6;i++)
                   {
                       ans = Math.min(ans,mat[i][r]-mat[i][l-1]);
                   }
                   fans.append(ans);
                   fans.append("\n");
               }
  			 out.println(fans);
   	}
   	    static int helper(StringBuilder str,String s,int l,int r)
          {
              int p=0;
              for (int i = l - 1; i < r; i++) {
                  if(str.charAt(i)!=s.charAt(i))
                  {
                      p++;
                  }
              }
              return p;
          }
  	}
  		static boolean isPalindrome(char[] s) {
  			int flag = 1;
  			for (int i = 0; i < s.length; i++) {
  				if (s[i] != s[s.length - 1 - i]) {
  					flag = 0;
  					break;
  				}
  			}
  			if (flag == 1) return true;
  			else return false;
  		}
  
  		static long gcd(long a, long b) {
  			if (b == 0) return a;
  			return gcd(b, a % b);
  		}
  
  		static boolean isSquare(double a) {
  			boolean isSq = false;
  			double b = Math.sqrt(a);
  			double c = Math.sqrt(a) - Math.floor(b);
  
  			if (c == 0) isSq = true;
  
  			return isSq;
  		}
  
  		static int exponentMod(int A, int B, int C) {
  
  			// Base cases
  			if (A == 0)
  				return 0;
  			if (B == 0)
  				return 1;
  
  			// If B is even
  			long y;
  			if (B % 2 == 0) {
  				y = exponentMod(A, B / 2, C);
  				y = (y * y) % C;
  			}
  
  			// If B is odd
  			else {
  				y = A % C;
  				y = (y * exponentMod(A, B - 1,
  						C) % C) % C;
  			}
  
  			return (int) ((y + C) % C);
  		}
  
  		public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
  			public U x;
  			public V y;
  
  			public Pair(U x, V y) {
  				this.x = x;
  				this.y = y;
  			}
  
  			public int hashCode() {
  				return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
  			}
  
  			public boolean equals(Object o) {
  				if (this == o)
  					return true;
  				if (o == null || getClass() != o.getClass())
  					return false;
  				Pair<U, V> p = (Pair<U, V>) o;
  				return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
  			}
  
  			public int compareTo(Pair<U, V> b) {
  				int cmpU = x.compareTo(b.x);
  				return cmpU != 0 ? cmpU : y.compareTo(b.y);
  			}
  
  			public String toString() {
  				return String.format("(%s, %s)", x.toString(), y.toString());
  			}
  
  		}
  
  		static class FastReader {
  			BufferedReader br;
  			StringTokenizer st;
  
  			public FastReader() {
  				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());
  			}
  
  			char nextChar() {
  				return next().charAt(0);
  			}
  
  			boolean nextBoolean() {
  				return !(nextInt() == 0);
  			}
  			// boolean nextBoolean(){return Boolean.parseBoolean(next());}
  
  			String nextLine() {
  				String str = "";
  				try {
  					str = br.readLine();
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  				return str;
  			}
  
  			public int[] readArray(int size) {
  				int[] array = new int[size];
  				for (int i = 0; i < size; i++) array[i] = nextInt();
  				return array;
  			}
  
  		}
  
  		private static int[] mergeSort(int[] array) {
  
  			if (array.length <= 1) {
  				return array;
  			}
  
  			int midpoint = array.length / 2;
  
  			int[] left = new int[midpoint];
  			int[] right;
  
  			if (array.length % 2 == 0) {
  				right = new int[midpoint];
  			} else {
  				right = new int[midpoint + 1];
  			}
  
  			for (int i = 0; i < left.length; i++) {
  				left[i] = array[i];
  			}
  
  			for (int i = 0; i < right.length; i++) {
  				right[i] = array[i + midpoint];
  			}
  
  			int[] result = new int[array.length];
  
  			left = mergeSort(left);
  			right = mergeSort(right);
  
  			result = merge(left, right);
  
  			return result;
  		}
  
  		private static int[] merge(int[] left, int[] right) {
  
  			int[] result = new int[left.length + right.length];
  			int leftPointer = 0, rightPointer = 0, resultPointer = 0;
  
  			while (leftPointer < left.length || rightPointer < right.length) {
  
  				if (leftPointer < left.length && rightPointer < right.length) {
  
  					if (left[leftPointer] < right[rightPointer]) {
  						result[resultPointer++] = left[leftPointer++];
  					} else {
  						result[resultPointer++] = right[rightPointer++];
  					}
  				} else if (leftPointer < left.length) {
  					result[resultPointer++] = left[leftPointer++];
  				} else {
  					result[resultPointer++] = right[rightPointer++];
  				}
  			}
  			return result;
  		}
  
  		public static void Sieve(int n) {
  
  			Arrays.fill(primecheck, true);
  			primecheck[0] = false;
  			primecheck[1] = false;
  
  			for (int i = 2; i * i < n + 1; i++) {
  				if (primecheck[i]) {
  					for (int j = i * 2; j < n + 1; j += i) {
  						primecheck[j] = false;
  					}
  				}
  			}
  		}
  
  	}
  
  
  