#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(void)
{
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vector<int> l(Q), r(Q);
    for (int i = 0; i < Q; i++)
    {
        cin >> l[i] >> r[i];
    }

    vector<int> acCount(N);
    acCount[0] = 0;
    for (int i = 1; i < N; i++)
    {
        if(S[i] == 'C' && S[i-1] == 'A'){
            acCount[i] = acCount[i-1]+1;
        } else {
            acCount[i] = acCount[i-1];
        }
    }
    
    for (int i = 0; i < Q; i++)
    {
        cout << acCount[r[i]-1] - acCount[l[i]-1] << endl;
    }
    
    
    return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<string>

using namespace std;

int main(){
	
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		int pre[n];
		string str;
		for(int i=0;i<n;i++){
			cin >> pre[i];
		}

		cin >> str;
			
		for(int i=0;i<str.size();i++){	
			for(int j=pre[i%n];j>0;j--){
				str[i]--;
				if(str[i]<=('A'-1)) str[i]='z';	
				if(str[i]==96 ) str[i] = 'Z';
			}
		}
		cout << str << endl;
	}
}