import java.util.Scanner;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int N, Q;
	N = sc.nextInt();
	Q = sc.nextInt();
	char S[] = (sc.next()).toCharArray();
	int l[] = new int[Q];
	int r[] = new int[Q];
	for (int i = 0; i < Q; i++) {
	    l[i] = sc.nextInt();
	    r[i] = sc.nextInt();
	}

	int t[] = new int[N];
	t[0] = 0;
	for (int i = 1; i < N; i++) {
	    if (S[i] == 'C' && S[i - 1] == 'A') {
		t[i] = t[i - 1] + 1;
	    } else {
		t[i] = t[i - 1];
	    }
	}

	for (int i = 0; i < Q; i++) {
	    System.out.println(t[r[i] - 1] - t[l[i] - 1]);
	}
	
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int N, Q;
	N = sc.nextInt();
	Q = sc.nextInt();
	char S[] = (sc.next()).toCharArray();
	int l[] = new int[Q];
	int r[] = new int[Q];
	for (int i = 0; i < Q; i++) {
	    l[i] = sc.nextInt();
	    r[i] = sc.nextInt();
	}

	int t[] = new int[N];
	t[0] = 0;
	for (int i = 1; i < N; i++) {
	    if (S[i] == 'C' && S[i - 1] == 'A') {
		t[i] = t[i - 1] + 1;
	    } else {
		t[i] = t[i - 1];
	    }
	}

	for (int i = 0; i < Q; i++) {
	    System.out.println(t[r[i] - 1] - t[l[i] - 1]);
	}
	
    }
} Main public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int N, Q;
	N = sc.nextInt();
	Q = sc.nextInt();
	char S[] = (sc.next()).toCharArray();
	int l[] = new int[Q];
	int r[] = new int[Q];
	for (int i = 0; i < Q; i++) {
	    l[i] = sc.nextInt();
	    r[i] = sc.nextInt();
	}

	int t[] = new int[N];
	t[0] = 0;
	for (int i = 1; i < N; i++) {
	    if (S[i] == 'C' && S[i - 1] == 'A') {
		t[i] = t[i - 1] + 1;
	    } else {
		t[i] = t[i - 1];
	    }
	}

	for (int i = 0; i < Q; i++) {
	    System.out.println(t[r[i] - 1] - t[l[i] - 1]);
	}
	
    } main {
	Scanner sc = new Scanner(System.in);

	int N, Q;
	N = sc.nextInt();
	Q = sc.nextInt();
	char S[] = (sc.next()).toCharArray();
	int l[] = new int[Q];
	int r[] = new int[Q];
	for (int i = 0; i < Q; i++) {
	    l[i] = sc.nextInt();
	    r[i] = sc.nextInt();
	}

	int t[] = new int[N];
	t[0] = 0;
	for (int i = 1; i < N; i++) {
	    if (S[i] == 'C' && S[i - 1] == 'A') {
		t[i] = t[i - 1] + 1;
	    } else {
		t[i] = t[i - 1];
	    }
	}

	for (int i = 0; i < Q; i++) {
	    System.out.println(t[r[i] - 1] - t[l[i] - 1]);
	}
	
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N N Q; Q N = sc.nextInt() N sc.nextInt() sc.nextInt sc Q = sc.nextInt() Q sc.nextInt() sc.nextInt sc char S[] = (sc.next()).toCharArray(); S (sc.next()).toCharArray() (sc.next()).toCharArray (sc.next()) sc.next sc int l[] = new int[Q]; l new int[Q] Q int r[] = new int[Q]; r new int[Q] Q for (int i = 0; i < Q; i++) {
	    l[i] = sc.nextInt();
	    r[i] = sc.nextInt();
	} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
	    l[i] = sc.nextInt();
	    r[i] = sc.nextInt();
	} {
	    l[i] = sc.nextInt();
	    r[i] = sc.nextInt();
	} l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc int t[] = new int[N]; t new int[N] N t[0] = 0 t[0] t 0 0 for (int i = 1; i < N; i++) {
	    if (S[i] == 'C' && S[i - 1] == 'A') {
		t[i] = t[i - 1] + 1;
	    } else {
		t[i] = t[i - 1];
	    }
	} int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
	    if (S[i] == 'C' && S[i - 1] == 'A') {
		t[i] = t[i - 1] + 1;
	    } else {
		t[i] = t[i - 1];
	    }
	} {
	    if (S[i] == 'C' && S[i - 1] == 'A') {
		t[i] = t[i - 1] + 1;
	    } else {
		t[i] = t[i - 1];
	    }
	} if (S[i] == 'C' && S[i - 1] == 'A') {
		t[i] = t[i - 1] + 1;
	    } else {
		t[i] = t[i - 1];
	    } S[i] == 'C' && S[i - 1] == 'A' S[i] == 'C' S[i] S i 'C' S[i - 1] == 'A' S[i - 1] S i - 1 i 1 'A' {
		t[i] = t[i - 1] + 1;
	    } t[i] = t[i - 1] + 1 t[i] t i t[i - 1] + 1 t[i - 1] t i - 1 i 1 1 {
		t[i] = t[i - 1];
	    } t[i] = t[i - 1] t[i] t i t[i - 1] t i - 1 i 1 for (int i = 0; i < Q; i++) {
	    System.out.println(t[r[i] - 1] - t[l[i] - 1]);
	} int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
	    System.out.println(t[r[i] - 1] - t[l[i] - 1]);
	} {
	    System.out.println(t[r[i] - 1] - t[l[i] - 1]);
	} System.out.println(t[r[i] - 1] - t[l[i] - 1]) System.out.println System.out System System.out t[r[i] - 1] - t[l[i] - 1] t[r[i] - 1] t r[i] - 1 r[i] r i 1 t[l[i] - 1] t l[i] - 1 l[i] l i 1 String[] args args
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int N, Q;
	N = sc.nextInt();
	Q = sc.nextInt();
	char S[] = (sc.next()).toCharArray();
	int l[] = new int[Q];
	int r[] = new int[Q];
	for (int i = 0; i < Q; i++) {
	    l[i] = sc.nextInt();
	    r[i] = sc.nextInt();
	}

	int t[] = new int[N];
	t[0] = 0;
	for (int i = 1; i < N; i++) {
	    if (S[i] == 'C' && S[i - 1] == 'A') {
		t[i] = t[i - 1] + 1;
	    } else {
		t[i] = t[i - 1];
	    }
	}

	for (int i = 0; i < Q; i++) {
	    System.out.println(t[r[i] - 1] - t[l[i] - 1]);
	}
	
    }
}