#include #include #include using namespace std; using namespace __gnu_pbds; #define mod 1000000007 #define MAX 1000000000000000 #define all(v) v.begin(),v.end() #define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++) #define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--) #define ii pair > #define MP make_pair #define pb push_back #define f first #define se second #define ll long long int #define vi vector ll modexp(ll a,ll b){ ll res = 1; while(b > 0){ if(b & 1) res = (res * a)%mod; a = (a * a)%mod; b/=2; } return res; } #define rs resize typedef tree< ll, null_type, less, rb_tree_tag, tree_order_statistics_node_update > OST; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; } template void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } #else #define trace(...) #endif const ll N = 100009,M = 26; ll i,n,q,l,r,j,c,ans,o; string a; ll fr[M][N],fact[N]; bool cmp(ll a,ll b) { return a > b; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); fact[0] = fact[1] = 1; rep(i,2,N) fact[i] = (fact[i - 1] * i)%mod; cin>>a; n = a.length(); rep(i,1,n + 1) fr[a[i - 1] - 'a'][i] = 1; rep(i,0,M) rep(j,1,n + 1) fr[i][j] += fr[i][j - 1]; cin>>q; while(q--){ cin>>l>>r; vi v; rep(i,0,M){ j = fr[i][r] - fr[i][l - 1]; if(j) v.pb(j); } sort(all(v),cmp); bool odd = 0; n = v.size(); c = o = 0; rep(i,0,n){ if(v[i]&1){ if(odd) c += v[i] - 1; else c += v[i]; odd = true; o++; } else c += v[i]; } ans = fact[c/2]; rep(i,0,n) ans = (ans * modexp(fact[v[i]/2],mod - 2))%mod; if(c&1) ans = (ans * o)%mod; cout<