#include #define int long long using namespace std; const int N = 1e5 + 5, M = 26, mod = 1e9 + 7; string s; int n, m, l, r, dp[M][N], f[N], of[N]; int binpow(int x, int y){ int res = 1; while(y){ if(y & 1){ res = (res * x) % mod; } x = (x * x) % mod; y >>= 1; } return res; } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); f[0] = of[0] = 1; for(int i = 1; i < N; i++){ f[i] = f[i - 1] * i % mod; of[i] = binpow(f[i], mod - 2); } cin >> s; n = s.size(); s = '#' + s; for(int i = 1; i <= n; i++){ for(int j = 0; j < M; j++){ dp[j][i] = dp[j][i - 1]; } dp[s[i] - 'a'][i]++; } cin >> m; for(int i = 1; i <= m; i++){ cin >> l >> r; int cnt[26]; for(int j = 0; j < M; j++){ cnt[j] = dp[j][r] - dp[j][l - 1]; } int kolvo = 0; for(int j = 0; j < M; j++){ if(cnt[j] & 1){ kolvo++; } } if(!kolvo){ int ans = f[(r - l + 1) / 2]; for(int j = 0; j < M; j++){ ans *= of[cnt[j] / 2]; ans %= mod; } //cout << i << " ONE "; cout << ans << "\n"; } else{ int o = 0; for(int j = 0; j < M; j++){ o += cnt[j] / 2; } //cout << o << " "; int ans = f[o]; for(int j = 0; j < M; j++){ ans *= of[cnt[j] / 2]; ans %= mod; } //cout << i << " TWO "; cout << ans * kolvo % mod << "\n"; } } } /** aaacccbb 1 1 8 */