#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int MAX = 522133279; const double pi = 3.1415926535897; const int mod = 9973; const int MAXN = 100000; int N; char s[MAXN + 100]; long long arr[MAXN + 100]; LL qpow( int a, int n ) { int temp=a; int ans=1; while ( n > 0 ) { if ( n & 1 ) ans=( ans*temp ) % mod; temp=( temp*temp ) % mod; n>>=1; } return ans; } LL lst; int main( ) { while ( ~scanf( "%d", &N ) ) { getchar( ); gets( s ); int len = strlen( s ); for ( int i = 1; i <= len; i++ ) { arr[i]=s[i - 1] - 28; if ( i > 1 ) arr[i] = ( arr[i - 1] * arr[i] ) % mod; } int a, b; while ( N-- ) { LL x, y; scanf( "%d %d", &a, &b ); getchar( ); if ( a < 1 || b > len ) { printf( "%I64d\n", lst ); continue; } if ( a > 1 ) { lst = ( arr[b] * ( qpow(arr[a-1], mod-2) ) ) % mod; } else { lst = arr[b] % mod; } printf( "%I64d\n", lst ); } } return 0; }