#include<iostream>
#include<stdio.h>
#define LL long long
#define mo 9973
using namespace std;
LL qmod(LL a,LL b)
{
LL sum=1;
while(b)
{
if(b&1) sum=(sum*a)%mo;
b>>=1;
a=(a*a)%mo;
}
return sum;
}
int main()
{
int n,i,a,b;
string str;
LL s[100005];
while(scanf("%d",&n)!=EOF)
{
cin>>str;
s[0]=1;
for(long i=1;i<=str.length();i++)
s[i]=(s[i-1])*(str[i-1]-28)% mo;
for(int i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
if(a>b) swap(a,b);
printf("%ld\n",(s[b]*(qmod(s[a-1],mo-2)%mo))%mo);
}
}
return 0;
}