#include #include #include #include #include #define ll long long using namespace std; ll md = 1e9+7 ; ll inv( ll x ) { if( x <= 1 ) return 1 ; int p = md-2 ; ll r(1) ; while( p > 0 ) { if( p%2 == 1 ) { r = (r*x)%md ; p-- ; } else { x = (x*x)%md ; p /= 2 ; } } return r ; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ string s ; cin >> s ; int n = s.length() ; vector< ll > rem(n/2+1) ; rem[0] = 1 ; for( ll i = 1 ; i < rem.size() ; i++ ) rem[i] = ( rem[i-1] * i )%md ; vector< vector< ll > > vv( n , vector< ll >(26,0) ) ; vv[0][ int( s[0] - 'a' ) ]++ ; for( int i = 1 ; i < n ; i++ ) { vv[i] = vv[i-1] ; vv[i][ int( s[i] - 'a' ) ]++ ; } int q(0) ; cin >> q ; while( q-- ) { int l , r ; cin >> l >> r ; l-- ; r-- ; vector< ll > t(26,0) ; for( int i = 0 ; i < 26 ; i++ ) t[i] = vv[r][i] - vv[l][i] ; t[ int( s[l] - 'a' ) ]++ ; ll ods(0) ; bool fo(0) ; ll len(0) ; ll res(1) ; for( int i = 0 ; i < 26 ; i++ ) { if( t[i]%2 == 1 ) { ods++ ; fo = 1 ; } t[i] /= 2 ; res = ( res * inv( rem[ t[i] ] ) )%md ; len += t[i] ; } res = ( res* rem[len] )%md ; if( fo == 1 ) res = ( res*ods )%md ; cout << res << endl ; } return 0; }