import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String strs[] = br.readLine().split(" ");
    String s = br.readLine();
    int N = Integer.parseInt(strs[0]), Q = Integer.parseInt(strs[1]);
    int index = 1;
    int[] ac = new int[s.length() + 1];
    for (int i = 0; i < s.length(); i++) {
      if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      }
      index++;
    }
    for (int i = 0; i < Q; i++) {
      String[] str = br.readLine().split(" ");
      int start = Integer.parseInt(str[0]), end = Integer.parseInt(str[1]);
      System.out.println(ac[end] - ac[start]);
    }
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String strs[] = br.readLine().split(" ");
    String s = br.readLine();
    int N = Integer.parseInt(strs[0]), Q = Integer.parseInt(strs[1]);
    int index = 1;
    int[] ac = new int[s.length() + 1];
    for (int i = 0; i < s.length(); i++) {
      if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      }
      index++;
    }
    for (int i = 0; i < Q; i++) {
      String[] str = br.readLine().split(" ");
      int start = Integer.parseInt(str[0]), end = Integer.parseInt(str[1]);
      System.out.println(ac[end] - ac[start]);
    }
  }
} Main public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String strs[] = br.readLine().split(" ");
    String s = br.readLine();
    int N = Integer.parseInt(strs[0]), Q = Integer.parseInt(strs[1]);
    int index = 1;
    int[] ac = new int[s.length() + 1];
    for (int i = 0; i < s.length(); i++) {
      if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      }
      index++;
    }
    for (int i = 0; i < Q; i++) {
      String[] str = br.readLine().split(" ");
      int start = Integer.parseInt(str[0]), end = Integer.parseInt(str[1]);
      System.out.println(ac[end] - ac[start]);
    }
  } main {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String strs[] = br.readLine().split(" ");
    String s = br.readLine();
    int N = Integer.parseInt(strs[0]), Q = Integer.parseInt(strs[1]);
    int index = 1;
    int[] ac = new int[s.length() + 1];
    for (int i = 0; i < s.length(); i++) {
      if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      }
      index++;
    }
    for (int i = 0; i < Q; i++) {
      String[] str = br.readLine().split(" ");
      int start = Integer.parseInt(str[0]), end = Integer.parseInt(str[1]);
      System.out.println(ac[end] - ac[start]);
    }
  } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String strs[] = br.readLine().split(" "); strs br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " String s = br.readLine(); s br.readLine() br.readLine br int N = Integer.parseInt(strs[0]) N Integer.parseInt(strs[0]) Integer.parseInt Integer strs[0] strs 0 Q = Integer.parseInt(strs[1]); Q Integer.parseInt(strs[1]) Integer.parseInt Integer strs[1] strs 1 int index = 1; index 1 int[] ac = new int[s.length() + 1]; ac new int[s.length() + 1] s.length() + 1 s.length() s.length s 1 for (int i = 0; i < s.length(); i++) {
      if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      }
      index++;
    } int i = 0; int i = 0; i 0 i < s.length() i s.length() s.length s i++ i++ i {
      if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      }
      index++;
    } {
      if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      }
      index++;
    } if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      } i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i) i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i) i - 1 >= 0 i - 1 i 1 0 'A' == s.charAt(i - 1) 'A' s.charAt(i - 1) s.charAt s i - 1 i 1 'C' == s.charAt(i) 'C' s.charAt(i) s.charAt s i {
        ac[index] = ac[index - 1] + 1;
      } ac[index] = ac[index - 1] + 1 ac[index] ac index ac[index - 1] + 1 ac[index - 1] ac index - 1 index 1 1 {
        ac[index] = ac[index - 1];
      } ac[index] = ac[index - 1] ac[index] ac index ac[index - 1] ac index - 1 index 1 index++ index for (int i = 0; i < Q; i++) {
      String[] str = br.readLine().split(" ");
      int start = Integer.parseInt(str[0]), end = Integer.parseInt(str[1]);
      System.out.println(ac[end] - ac[start]);
    } int i = 0; int i = 0; i 0 i < Q i Q i++ i++ i {
      String[] str = br.readLine().split(" ");
      int start = Integer.parseInt(str[0]), end = Integer.parseInt(str[1]);
      System.out.println(ac[end] - ac[start]);
    } {
      String[] str = br.readLine().split(" ");
      int start = Integer.parseInt(str[0]), end = Integer.parseInt(str[1]);
      System.out.println(ac[end] - ac[start]);
    } String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int start = Integer.parseInt(str[0]) start Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 end = Integer.parseInt(str[1]); end Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 System.out.println(ac[end] - ac[start]) System.out.println System.out System System.out ac[end] - ac[start] ac[end] ac end ac[start] ac start String[] args args public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String strs[] = br.readLine().split(" ");
    String s = br.readLine();
    int N = Integer.parseInt(strs[0]), Q = Integer.parseInt(strs[1]);
    int index = 1;
    int[] ac = new int[s.length() + 1];
    for (int i = 0; i < s.length(); i++) {
      if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      }
      index++;
    }
    for (int i = 0; i < Q; i++) {
      String[] str = br.readLine().split(" ");
      int start = Integer.parseInt(str[0]), end = Integer.parseInt(str[1]);
      System.out.println(ac[end] - ac[start]);
    }
  }
} public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String strs[] = br.readLine().split(" ");
    String s = br.readLine();
    int N = Integer.parseInt(strs[0]), Q = Integer.parseInt(strs[1]);
    int index = 1;
    int[] ac = new int[s.length() + 1];
    for (int i = 0; i < s.length(); i++) {
      if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      }
      index++;
    }
    for (int i = 0; i < Q; i++) {
      String[] str = br.readLine().split(" ");
      int start = Integer.parseInt(str[0]), end = Integer.parseInt(str[1]);
      System.out.println(ac[end] - ac[start]);
    }
  }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String strs[] = br.readLine().split(" ");
    String s = br.readLine();
    int N = Integer.parseInt(strs[0]), Q = Integer.parseInt(strs[1]);
    int index = 1;
    int[] ac = new int[s.length() + 1];
    for (int i = 0; i < s.length(); i++) {
      if (i - 1 >= 0 && 'A' == s.charAt(i - 1) && 'C' == s.charAt(i)) {
        ac[index] = ac[index - 1] + 1;
      } else {
        ac[index] = ac[index - 1];
      }
      index++;
    }
    for (int i = 0; i < Q; i++) {
      String[] str = br.readLine().split(" ");
      int start = Integer.parseInt(str[0]), end = Integer.parseInt(str[1]);
      System.out.println(ac[end] - ac[start]);
    }
  }
}
