import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    char s[] = sc.next().toCharArray();
    int cntarr[] = new int[n];
    cntarr[0] = 0;
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
      if ('A' == s[i] && 'C' == s[i + 1]) cnt++;
      cntarr[i + 1] = cnt;
    }
    for (int i = 0;i < q;i ++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(cntarr[r-1]-cntarr[l-1]);
    }
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    char s[] = sc.next().toCharArray();
    int cntarr[] = new int[n];
    cntarr[0] = 0;
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
      if ('A' == s[i] && 'C' == s[i + 1]) cnt++;
      cntarr[i + 1] = cnt;
    }
    for (int i = 0;i < q;i ++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(cntarr[r-1]-cntarr[l-1]);
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    char s[] = sc.next().toCharArray();
    int cntarr[] = new int[n];
    cntarr[0] = 0;
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
      if ('A' == s[i] && 'C' == s[i + 1]) cnt++;
      cntarr[i + 1] = cnt;
    }
    for (int i = 0;i < q;i ++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(cntarr[r-1]-cntarr[l-1]);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    char s[] = sc.next().toCharArray();
    int cntarr[] = new int[n];
    cntarr[0] = 0;
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
      if ('A' == s[i] && 'C' == s[i + 1]) cnt++;
      cntarr[i + 1] = cnt;
    }
    for (int i = 0;i < q;i ++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(cntarr[r-1]-cntarr[l-1]);
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int 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 cntarr[] = new int[n]; cntarr new int[n] n cntarr[0] = 0 cntarr[0] cntarr 0 0 int cnt = 0; cnt 0 for (int i = 0; i < n - 1; i++) {
      if ('A' == s[i] && 'C' == s[i + 1]) cnt++;
      cntarr[i + 1] = cnt;
    } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
      if ('A' == s[i] && 'C' == s[i + 1]) cnt++;
      cntarr[i + 1] = cnt;
    } {
      if ('A' == s[i] && 'C' == s[i + 1]) cnt++;
      cntarr[i + 1] = cnt;
    } if ('A' == s[i] && 'C' == s[i + 1]) cnt++; 'A' == s[i] && 'C' == s[i + 1] 'A' == s[i] 'A' s[i] s i 'C' == s[i + 1] 'C' s[i + 1] s i + 1 i 1 cnt++ cnt cntarr[i + 1] = cnt cntarr[i + 1] cntarr i + 1 i 1 cnt for (int i = 0;i < q;i ++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(cntarr[r-1]-cntarr[l-1]);
    } int i = 0; int i = 0; i 0 i < q i q i ++ i ++ i {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(cntarr[r-1]-cntarr[l-1]);
    } {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(cntarr[r-1]-cntarr[l-1]);
    } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc System.out.println(cntarr[r-1]-cntarr[l-1]) System.out.println System.out System System.out cntarr[r-1]-cntarr[l-1] cntarr[r-1] cntarr r-1 r 1 cntarr[l-1] cntarr l-1 l 1 String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    char s[] = sc.next().toCharArray();
    int cntarr[] = new int[n];
    cntarr[0] = 0;
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
      if ('A' == s[i] && 'C' == s[i + 1]) cnt++;
      cntarr[i + 1] = cnt;
    }
    for (int i = 0;i < q;i ++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(cntarr[r-1]-cntarr[l-1]);
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    char s[] = sc.next().toCharArray();
    int cntarr[] = new int[n];
    cntarr[0] = 0;
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
      if ('A' == s[i] && 'C' == s[i + 1]) cnt++;
      cntarr[i + 1] = cnt;
    }
    for (int i = 0;i < q;i ++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(cntarr[r-1]-cntarr[l-1]);
    }
  }
} Main
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    char s[] = sc.next().toCharArray();
    int cntarr[] = new int[n];
    cntarr[0] = 0;
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
      if ('A' == s[i] && 'C' == s[i + 1]) cnt++;
      cntarr[i + 1] = cnt;
    }
    for (int i = 0;i < q;i ++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      System.out.println(cntarr[r-1]-cntarr[l-1]);
    }
  }
}