#include #include #include #include #include #include #include using namespace std; #define maxN 100005 char str[maxN]; int h[maxN]; int M = 9973; //****************************** //返回d=gcd(a,b);和对应于等式ax+by=d中的x,y long long extend_gcd(long long a,long long b,long long &x,long long &y) { if(a==0&&b==0) return -1;//无最大公约数 if(b==0){x=1;y=0;return a;} long long d=extend_gcd(b,a%b,y,x); y-=a/b*x; return d; } //*********求逆元素******************* //ax = 1(mod n) long long mod_reverse(long long a,long long n) { long long x,y; long long d=extend_gcd(a,n,x,y); if(d==1) return (x%n+n)%n; else return -1; } int main(){ int N; while(scanf("%d",&N)!=EOF){ scanf("%s",str+1); int l = strlen(str+1); h[0] = 1; h[1] = str[1]-28; for(int i=2;i<=l;i++){ h[i] = (h[i-1]*(str[i]-28))%M; } while(N--){ int a,b; scanf("%d %d",&a,&b); int ans = (h[b]*mod_reverse(h[a-1],M))%M; printf("%d\n",ans); } } return 0; }