/* * Author: * Indestinee * Date: * 2016/05/14 */ #include #include #include #include #include #include #include #include #include using namespace std; #define hash hahahahaha int n, l, r, len, hash[123456], arhash[123456]; char a[123456]; const int mod = 9973; int quickpow( int x , int b ){ int ret = 1; while( b ){ if( b & 1 ) ret = ret * x % mod; x = x * x % mod; b >>= 1; } return ret; } int main(){ // freopen( "A.in" , "r" , stdin ); // freopen( "A.out" , "w" , stdout ); hash[0] = arhash[0] = 1; while( scanf( "%d" , &n ) != EOF ){ scanf( "%s" , a + 1 ); len = strlen( a + 1 ); for( int i = 1 ; i <= len ; i ++ ){ hash[i] = hash[i-1] * ( a[i] - 28 ) % mod; arhash[i] = quickpow( hash[i] , mod-2 ); } while( n -- ){ scanf( "%d%d" , &l , &r ); printf( "%d\n" , hash[r] * arhash[l-1] % mod ); } } return 0; }