#include <iostream>
#include <string>
#include <sstream>
#include <stdio.h>
using namespace std;
int main(){
string str,wstr;
string s;
int N;
cin >> N;
cin >> wstr;
int a, b;
int ret = 1;
for (int i = 0; i < N;i++){
cin >> a >> b;
if (a>wstr.size() || b > wstr.size() || a < 1 || b < 1 || a > b){
continue;
}
ret = 1;
for (int j = a; j <= b;j++){
ret *= ((char)wstr[j-1] - 28);
ret = ret % 9973;
}
cout << ret << endl;
}
return 0;
}