import java.io.*;
import java.util.StringTokenizer;

public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st =new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int Q = Integer.parseInt(st.nextToken());
        char[] arr = br.readLine().toCharArray();
        int[] num = new int[N];
        num[0] = 0;
        for(int i=1;i<N;++i)
        {
            num[i] = num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0);
        }
        for(int i=0;i<Q;++i)
        {
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            bw.write((num[end-1] - num[start-1]) +"\n");
        }
        bw.close();

    }
} import java.io.*; io.* java import java.util.StringTokenizer; StringTokenizer java.util public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st =new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int Q = Integer.parseInt(st.nextToken());
        char[] arr = br.readLine().toCharArray();
        int[] num = new int[N];
        num[0] = 0;
        for(int i=1;i<N;++i)
        {
            num[i] = num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0);
        }
        for(int i=0;i<Q;++i)
        {
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            bw.write((num[end-1] - num[start-1]) +"\n");
        }
        bw.close();

    }
} Main public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st =new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int Q = Integer.parseInt(st.nextToken());
        char[] arr = br.readLine().toCharArray();
        int[] num = new int[N];
        num[0] = 0;
        for(int i=1;i<N;++i)
        {
            num[i] = num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0);
        }
        for(int i=0;i<Q;++i)
        {
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            bw.write((num[end-1] - num[start-1]) +"\n");
        }
        bw.close();

    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st =new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int Q = Integer.parseInt(st.nextToken());
        char[] arr = br.readLine().toCharArray();
        int[] num = new int[N];
        num[0] = 0;
        for(int i=1;i<N;++i)
        {
            num[i] = num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0);
        }
        for(int i=0;i<Q;++i)
        {
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            bw.write((num[end-1] - num[start-1]) +"\n");
        }
        bw.close();

    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); bw new BufferedWriter(new OutputStreamWriter(System.out)) StringTokenizer st =new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) int N = Integer.parseInt(st.nextToken()); N Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int Q = Integer.parseInt(st.nextToken()); Q Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st char[] arr = br.readLine().toCharArray(); arr br.readLine().toCharArray() br.readLine().toCharArray br.readLine() br.readLine br int[] num = new int[N]; num new int[N] N num[0] = 0 num[0] num 0 0 for(int i=1;i<N;++i)
        {
            num[i] = num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0);
        } int i=1; int i=1; i 1 i<N i N ++i ++i i {
            num[i] = num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0);
        } {
            num[i] = num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0);
        } num[i] = num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0) num[i] num i num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0) num[i-1] num i-1 i 1 (arr[i-1]=='A'&&arr[i]=='C'?1:0) arr[i-1]=='A'&&arr[i]=='C' arr[i-1]=='A' arr[i-1] arr i-1 i 1 'A' arr[i]=='C' arr[i] arr i 'C' 1 0 for(int i=0;i<Q;++i)
        {
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            bw.write((num[end-1] - num[start-1]) +"\n");
        } int i=0; int i=0; i 0 i<Q i Q ++i ++i i {
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            bw.write((num[end-1] - num[start-1]) +"\n");
        } {
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            bw.write((num[end-1] - num[start-1]) +"\n");
        } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) int start = Integer.parseInt(st.nextToken()); start Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int end = Integer.parseInt(st.nextToken()); end Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st bw.write((num[end-1] - num[start-1]) +"\n") bw.write bw (num[end-1] - num[start-1]) +"\n" (num[end-1] - num[start-1]) num[end-1] num end-1 end 1 num[start-1] num start-1 start 1 "\n" bw.close() bw.close bw String[] args args public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st =new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int Q = Integer.parseInt(st.nextToken());
        char[] arr = br.readLine().toCharArray();
        int[] num = new int[N];
        num[0] = 0;
        for(int i=1;i<N;++i)
        {
            num[i] = num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0);
        }
        for(int i=0;i<Q;++i)
        {
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            bw.write((num[end-1] - num[start-1]) +"\n");
        }
        bw.close();

    }
} public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st =new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int Q = Integer.parseInt(st.nextToken());
        char[] arr = br.readLine().toCharArray();
        int[] num = new int[N];
        num[0] = 0;
        for(int i=1;i<N;++i)
        {
            num[i] = num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0);
        }
        for(int i=0;i<Q;++i)
        {
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            bw.write((num[end-1] - num[start-1]) +"\n");
        }
        bw.close();

    }
} Main
import java.io.*;
import java.util.StringTokenizer;

public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st =new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int Q = Integer.parseInt(st.nextToken());
        char[] arr = br.readLine().toCharArray();
        int[] num = new int[N];
        num[0] = 0;
        for(int i=1;i<N;++i)
        {
            num[i] = num[i-1] + (arr[i-1]=='A'&&arr[i]=='C'?1:0);
        }
        for(int i=0;i<Q;++i)
        {
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            bw.write((num[end-1] - num[start-1]) +"\n");
        }
        bw.close();

    }
}
