#include <iostream>
#include <vector>
#include <algorithm>
int main() {
    std::vector<int> v;
    std::vector<int> w;
    int n;
    std::cin >> n;
    while (n-- > 0) {
        int m;
        std::cin >> m;
        v.push_back(m);
    }
    std::cin >> n;
    while (n-- > 0) {
        int m;
        std::cin >> m;
        w.push_back(m);
    }
    int c = 0;
    for (auto&& e: w) {
        if (std::find(v.begin(), v.end(), e) != v.end()) {
            ++c;
        }
    }
    std::cout << c << std::endl;
}


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;
typedef long long ll;

int main() {
    int N, Q;
    string S;
    cin >> N >> Q;
    cin >> S;
    vector<vector<int>> data(Q, vector<int>(2));
    for (int i = 0; i < Q; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> data.at(i).at(j);
        }
    }
    vector<int> rsum(N + 1, 0);
    int sum = 0;
    for (int i = 0; i < N - 1; i++) {
        if (S.at(i) == 'A' && S.at(i + 1) == 'C') {
            sum++;
        }
        rsum.at(i + 1) = sum;
    }
    int ans;
    for (int i = 0; i < Q; i++) {
        ans = rsum.at(data.at(i).at(1) - 1) - rsum.at(data.at(i).at(0) - 1);
        cout << ans << endl;
    }
}