#include #define loop(i,n) for( ll i=0; i::iterator i=a.begin(); i!=a.end(); i++ ) #define dloop(i,a) for( deque::iterator i=a.begin(); i!=a.end(); i++ ) #define PI 3.14159265 #define bc __builtin_popcountll #define gc getchar_unlocked #define pc putchar_unlocked #define pb push_back #define pf push_front #define rf pop_front #define rb pop_back #define mp make_pair #define fs first #define sc second #define fi ios_base::sync_with_stdio(false); cin.tie(NULL) using namespace std; typedef long long ll; typedef unsigned long long ull; const ll M = 1e9 + 7; const ll INF = 1e9; inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;} const int sz = (int)1e5 + 10; string s; ll q, cnt[sz][30], len, l, r; int main() { fi; cin>>s; cin>>q; len = s.length(); memset(cnt,0,sizeof(cnt)); loop(i,len) { cnt[i+1][s[i]-97]++; if( i > 0) { loop(j,26) { cnt[i+1][j] += cnt[i][j]; } } } ll ff[sz]; ff[0] = 1; loop1(i,1,len+1) { ff[i] = (i*ff[i-1]) % M; } while(q--) { cin>>l>>r; ll l1 = 0, red = 1; ll cntr = 0; loop(i,26) { ll v = ( cnt[r][i] - cnt[l-1][i] ); l1 += v/2; red = (red*ff[v/2]) % M; cntr += v%2; } ll ans = ff[l1]; if( cntr != 0 ) { ans = (ans*cntr) % M; } ans = ( ans*pwr(red,M-2,M) ) % M; cout<