//Copyright © 2017 Snehil Santhalia #include using namespace std; typedef long long ll; typedef long double ld; typedef vector vi; typedef vector vvi; typedef pair ii; typedef vector vii; typedef vector vvii; #define INF 1e18 #define loop(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++) #define forit(i, a) for ( __typeof( (a).begin() ) i = (a).begin(); i != (a).end(); i++ ) #define mem(a, v) memset(a, v, sizeof a) #define pb push_back #define mp make_pair #define MOD 1000000007 #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) #define left(x) x<<1 #define right(x) (x<<1)|1 #define PI acos(-1.0) #define EPS 1e-9 ll T = 1; ll arr[100505][30], q, l, r; ll fact[100050]; string s; ll fast_pow(long long base, long long n) { if(n==0) return 1; if(n==1) return base; long long halfn=fast_pow(base,n/2); if(n%2==0) return ( halfn * halfn ) % MOD; else return ( ( ( halfn * halfn ) % MOD ) * base ) % MOD; } ll findMMI_fermat(ll n) { return fast_pow(n, MOD-2); } void func() { fact[0] = 1; loop(i,1,100005) { fact[i] = (fact[i-1]*i)%MOD; } } void solve(){ cin >> s; loop(i,0,s.size()-1) arr[i+1][s[i]-'a']++; loop(i,1,s.size()) { loop(j,0,25) arr[i][j] += arr[i-1][j]; } cin >> q; vi v; loop(i,1,q) { cin >> l >> r; ll ans = 1, temp = 0, odd = 0, len = 0; v.clear(); loop(j,0,25) { temp = arr[r][j] - arr[l-1][j]; if(temp&1) odd++; len += temp/2; v.pb(temp/2); } ans = (ans * fact[len])%MOD; loop(i,0,v.size()-1) { ans = (ans * findMMI_fermat(fact[v[i]]))%MOD; } if(odd) ans = (ans * odd)%MOD; cout << ans << endl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //cin>>T; func(); while(T--){ solve(); } return 0; }