import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    int q = sc.nextInt();
    String s = sc.next();

    // zero-origin
    int[] l = new int[q];
    int[] r = new int[q];

    for (int i = 0; i < q; i++) {
      l[i] = sc.nextInt() - 1;
      r[i] = sc.nextInt() - 1;
    }

    List<Integer> acLeftIndexes = new ArrayList<>();

    // number of occurrence of AC [0.. i)
    int[] occurrences = new int[n];

    int occurrence = 0;
    for (int i = 1; i < n; i++) {
      if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      }
      occurrences[i] = occurrence;
    }

    for (int i = 0; i < q; i++) {
      os.println(occurrences[r[i]] - (occurrences[l[i]]));
    }
  }

} import java.io.InputStream; InputStream java.io import java.io.PrintStream; PrintStream java.io import java.util.*; util.* java public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    int q = sc.nextInt();
    String s = sc.next();

    // zero-origin
    int[] l = new int[q];
    int[] r = new int[q];

    for (int i = 0; i < q; i++) {
      l[i] = sc.nextInt() - 1;
      r[i] = sc.nextInt() - 1;
    }

    List<Integer> acLeftIndexes = new ArrayList<>();

    // number of occurrence of AC [0.. i)
    int[] occurrences = new int[n];

    int occurrence = 0;
    for (int i = 1; i < n; i++) {
      if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      }
      occurrences[i] = occurrence;
    }

    for (int i = 0; i < q; i++) {
      os.println(occurrences[r[i]] - (occurrences[l[i]]));
    }
  }

} Main public static void main(String[] args) {
    solve(System.in, System.out);
  } main {
    solve(System.in, System.out);
  } solve(System.in, System.out) solve System.in System System.in System.out System System.out String[] args args static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    int q = sc.nextInt();
    String s = sc.next();

    // zero-origin
    int[] l = new int[q];
    int[] r = new int[q];

    for (int i = 0; i < q; i++) {
      l[i] = sc.nextInt() - 1;
      r[i] = sc.nextInt() - 1;
    }

    List<Integer> acLeftIndexes = new ArrayList<>();

    // number of occurrence of AC [0.. i)
    int[] occurrences = new int[n];

    int occurrence = 0;
    for (int i = 1; i < n; i++) {
      if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      }
      occurrences[i] = occurrence;
    }

    for (int i = 0; i < q; i++) {
      os.println(occurrences[r[i]] - (occurrences[l[i]]));
    }
  } solve {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    int q = sc.nextInt();
    String s = sc.next();

    // zero-origin
    int[] l = new int[q];
    int[] r = new int[q];

    for (int i = 0; i < q; i++) {
      l[i] = sc.nextInt() - 1;
      r[i] = sc.nextInt() - 1;
    }

    List<Integer> acLeftIndexes = new ArrayList<>();

    // number of occurrence of AC [0.. i)
    int[] occurrences = new int[n];

    int occurrence = 0;
    for (int i = 1; i < n; i++) {
      if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      }
      occurrences[i] = occurrence;
    }

    for (int i = 0; i < q; i++) {
      os.println(occurrences[r[i]] - (occurrences[l[i]]));
    }
  } Scanner sc = new Scanner(is); sc new Scanner(is) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc String s = sc.next(); s 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() - 1;
      r[i] = sc.nextInt() - 1;
    } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
      l[i] = sc.nextInt() - 1;
      r[i] = sc.nextInt() - 1;
    } {
      l[i] = sc.nextInt() - 1;
      r[i] = sc.nextInt() - 1;
    } l[i] = sc.nextInt() - 1 l[i] l i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 r[i] = sc.nextInt() - 1 r[i] r i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 List<Integer> acLeftIndexes = new ArrayList<>(); acLeftIndexes new ArrayList<>() int[] occurrences = new int[n]; occurrences new int[n] n int occurrence = 0; occurrence 0 for (int i = 1; i < n; i++) {
      if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      }
      occurrences[i] = occurrence;
    } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
      if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      }
      occurrences[i] = occurrence;
    } {
      if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      }
      occurrences[i] = occurrence;
    } if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      } s.charAt(i - 1) == 'A' && s.charAt(i) == 'C' s.charAt(i - 1) == 'A' s.charAt(i - 1) s.charAt s i - 1 i 1 'A' s.charAt(i) == 'C' s.charAt(i) s.charAt s i 'C' {
        occurrence++;
      } occurrence++ occurrence occurrences[i] = occurrence occurrences[i] occurrences i occurrence for (int i = 0; i < q; i++) {
      os.println(occurrences[r[i]] - (occurrences[l[i]]));
    } int i = 0; int i = 0; i 0 i < q i q i++ i++ i {
      os.println(occurrences[r[i]] - (occurrences[l[i]]));
    } {
      os.println(occurrences[r[i]] - (occurrences[l[i]]));
    } os.println(occurrences[r[i]] - (occurrences[l[i]])) os.println os occurrences[r[i]] - (occurrences[l[i]]) occurrences[r[i]] occurrences r[i] r i (occurrences[l[i]]) occurrences l[i] l i InputStream is is PrintStream os os public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    int q = sc.nextInt();
    String s = sc.next();

    // zero-origin
    int[] l = new int[q];
    int[] r = new int[q];

    for (int i = 0; i < q; i++) {
      l[i] = sc.nextInt() - 1;
      r[i] = sc.nextInt() - 1;
    }

    List<Integer> acLeftIndexes = new ArrayList<>();

    // number of occurrence of AC [0.. i)
    int[] occurrences = new int[n];

    int occurrence = 0;
    for (int i = 1; i < n; i++) {
      if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      }
      occurrences[i] = occurrence;
    }

    for (int i = 0; i < q; i++) {
      os.println(occurrences[r[i]] - (occurrences[l[i]]));
    }
  }

} public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    int q = sc.nextInt();
    String s = sc.next();

    // zero-origin
    int[] l = new int[q];
    int[] r = new int[q];

    for (int i = 0; i < q; i++) {
      l[i] = sc.nextInt() - 1;
      r[i] = sc.nextInt() - 1;
    }

    List<Integer> acLeftIndexes = new ArrayList<>();

    // number of occurrence of AC [0.. i)
    int[] occurrences = new int[n];

    int occurrence = 0;
    for (int i = 1; i < n; i++) {
      if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      }
      occurrences[i] = occurrence;
    }

    for (int i = 0; i < q; i++) {
      os.println(occurrences[r[i]] - (occurrences[l[i]]));
    }
  }

} Main
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    int q = sc.nextInt();
    String s = sc.next();

    // zero-origin
    int[] l = new int[q];
    int[] r = new int[q];

    for (int i = 0; i < q; i++) {
      l[i] = sc.nextInt() - 1;
      r[i] = sc.nextInt() - 1;
    }

    List<Integer> acLeftIndexes = new ArrayList<>();

    // number of occurrence of AC [0.. i)
    int[] occurrences = new int[n];

    int occurrence = 0;
    for (int i = 1; i < n; i++) {
      if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      }
      occurrences[i] = occurrence;
    }

    for (int i = 0; i < q; i++) {
      os.println(occurrences[r[i]] - (occurrences[l[i]]));
    }
  }

}