import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) throws IOException {
		MScanner sc = new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();int q=sc.nextInt();
		int[]pref=new int[n];
		char[]in=sc.nextLine().toCharArray();
		pref[0]=0;
		for(int i=1;i<n;i++) {
			if(in[i]=='C' && in[i-1]=='A')
				pref[i]=pref[i-1]+1;
			else {
				pref[i]=pref[i-1];
			}
		}
		while(q-->0) {
			int l=sc.nextInt()-1;int r=sc.nextInt()-1;
			pw.println(pref[r]-pref[l]);
		}
		pw.flush();
 
	}
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.FileReader; FileReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.HashMap; HashMap java.util import java.util.HashSet; HashSet java.util import java.util.LinkedList; LinkedList java.util import java.util.PriorityQueue; PriorityQueue java.util import java.util.StringTokenizer; StringTokenizer java.util public class Main {
	public static void main(String[] args) throws IOException {
		MScanner sc = new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();int q=sc.nextInt();
		int[]pref=new int[n];
		char[]in=sc.nextLine().toCharArray();
		pref[0]=0;
		for(int i=1;i<n;i++) {
			if(in[i]=='C' && in[i-1]=='A')
				pref[i]=pref[i-1]+1;
			else {
				pref[i]=pref[i-1];
			}
		}
		while(q-->0) {
			int l=sc.nextInt()-1;int r=sc.nextInt()-1;
			pw.println(pref[r]-pref[l]);
		}
		pw.flush();
 
	}
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} Main public static void main(String[] args) throws IOException {
		MScanner sc = new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();int q=sc.nextInt();
		int[]pref=new int[n];
		char[]in=sc.nextLine().toCharArray();
		pref[0]=0;
		for(int i=1;i<n;i++) {
			if(in[i]=='C' && in[i-1]=='A')
				pref[i]=pref[i-1]+1;
			else {
				pref[i]=pref[i-1];
			}
		}
		while(q-->0) {
			int l=sc.nextInt()-1;int r=sc.nextInt()-1;
			pw.println(pref[r]-pref[l]);
		}
		pw.flush();
 
	} main {
		MScanner sc = new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();int q=sc.nextInt();
		int[]pref=new int[n];
		char[]in=sc.nextLine().toCharArray();
		pref[0]=0;
		for(int i=1;i<n;i++) {
			if(in[i]=='C' && in[i-1]=='A')
				pref[i]=pref[i-1]+1;
			else {
				pref[i]=pref[i-1];
			}
		}
		while(q-->0) {
			int l=sc.nextInt()-1;int r=sc.nextInt()-1;
			pw.println(pref[r]-pref[l]);
		}
		pw.flush();
 
	} MScanner sc = new MScanner(System.in); sc new MScanner(System.in) PrintWriter pw=new PrintWriter(System.out); pw new PrintWriter(System.out) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int q=sc.nextInt(); q sc.nextInt() sc.nextInt sc int[]pref=new int[n]; pref new int[n] n char[]in=sc.nextLine().toCharArray(); in sc.nextLine().toCharArray() sc.nextLine().toCharArray sc.nextLine() sc.nextLine sc pref[0]=0 pref[0] pref 0 0 for(int i=1;i<n;i++) {
			if(in[i]=='C' && in[i-1]=='A')
				pref[i]=pref[i-1]+1;
			else {
				pref[i]=pref[i-1];
			}
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			if(in[i]=='C' && in[i-1]=='A')
				pref[i]=pref[i-1]+1;
			else {
				pref[i]=pref[i-1];
			}
		} {
			if(in[i]=='C' && in[i-1]=='A')
				pref[i]=pref[i-1]+1;
			else {
				pref[i]=pref[i-1];
			}
		} if(in[i]=='C' && in[i-1]=='A')
				pref[i]=pref[i-1]+1;
			else {
				pref[i]=pref[i-1];
			} in[i]=='C' && in[i-1]=='A' in[i]=='C' in[i] in i 'C' in[i-1]=='A' in[i-1] in i-1 i 1 'A' pref[i]=pref[i-1]+1 pref[i] pref i pref[i-1]+1 pref[i-1] pref i-1 i 1 1 {
				pref[i]=pref[i-1];
			} pref[i]=pref[i-1] pref[i] pref i pref[i-1] pref i-1 i 1 while(q-->0) {
			int l=sc.nextInt()-1;int r=sc.nextInt()-1;
			pw.println(pref[r]-pref[l]);
		} q-->0 q-- q 0 {
			int l=sc.nextInt()-1;int r=sc.nextInt()-1;
			pw.println(pref[r]-pref[l]);
		} int l=sc.nextInt()-1; l sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int r=sc.nextInt()-1; r sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 pw.println(pref[r]-pref[l]) pw.println pw pref[r]-pref[l] pref[r] pref r pref[l] pref l pw.flush() pw.flush pw String[] args args static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	} MScanner StringTokenizer st; st BufferedReader br; br public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		} MScanner {
			br = new BufferedReader(new InputStreamReader(system));
		} br = new BufferedReader(new InputStreamReader(system)) br new BufferedReader(new InputStreamReader(system)) InputStream system system public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		} MScanner {
			br = new BufferedReader(new FileReader(file));
		} br = new BufferedReader(new FileReader(file)) br new BufferedReader(new FileReader(file)) String file file public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		} next {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		} while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine()); st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public String nextLine() throws IOException {
			return br.readLine();
		} nextLine {
			return br.readLine();
		} return br.readLine(); br.readLine() br.readLine br public int nextInt() throws IOException {
			return Integer.parseInt(next());
		} nextInt {
			return Integer.parseInt(next());
		} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		} nextDouble {
			return Double.parseDouble(next());
		} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public char nextChar() throws IOException {
			return next().charAt(0);
		} nextChar {
			return next().charAt(0);
		} return next().charAt(0); next().charAt(0) next().charAt next() next 0 public Long nextLong() throws IOException {
			return Long.parseLong(next());
		} nextLong {
			return Long.parseLong(next());
		} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public boolean ready() throws IOException {
			return br.ready();
		} ready {
			return br.ready();
		} return br.ready(); br.ready() br.ready br public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		} waitForInput {
			Thread.sleep(3000);
		} Thread.sleep(3000) Thread.sleep Thread 3000 public class Main {
	public static void main(String[] args) throws IOException {
		MScanner sc = new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();int q=sc.nextInt();
		int[]pref=new int[n];
		char[]in=sc.nextLine().toCharArray();
		pref[0]=0;
		for(int i=1;i<n;i++) {
			if(in[i]=='C' && in[i-1]=='A')
				pref[i]=pref[i-1]+1;
			else {
				pref[i]=pref[i-1];
			}
		}
		while(q-->0) {
			int l=sc.nextInt()-1;int r=sc.nextInt()-1;
			pw.println(pref[r]-pref[l]);
		}
		pw.flush();
 
	}
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		MScanner sc = new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();int q=sc.nextInt();
		int[]pref=new int[n];
		char[]in=sc.nextLine().toCharArray();
		pref[0]=0;
		for(int i=1;i<n;i++) {
			if(in[i]=='C' && in[i-1]=='A')
				pref[i]=pref[i-1]+1;
			else {
				pref[i]=pref[i-1];
			}
		}
		while(q-->0) {
			int l=sc.nextInt()-1;int r=sc.nextInt()-1;
			pw.println(pref[r]-pref[l]);
		}
		pw.flush();
 
	}
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} Main
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) throws IOException {
		MScanner sc = new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();int q=sc.nextInt();
		int[]pref=new int[n];
		char[]in=sc.nextLine().toCharArray();
		pref[0]=0;
		for(int i=1;i<n;i++) {
			if(in[i]=='C' && in[i-1]=='A')
				pref[i]=pref[i-1]+1;
			else {
				pref[i]=pref[i-1];
			}
		}
		while(q-->0) {
			int l=sc.nextInt()-1;int r=sc.nextInt()-1;
			pw.println(pref[r]-pref[l]);
		}
		pw.flush();
 
	}
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}