#include #include #include #include using namespace std; typedef long long LL; const int N = 100000+10; const LL MOD = 1000000007; char s[N]; int cnt[N][30], q; LL mpow(LL a, LL x) { if (x == 0) return 1; LL t = mpow(a, x/2); if (x%2==1) return t*t%MOD*a%MOD; return t*t%MOD; } LL f[N], inv[N]; void init() { f[0] = inv[0] = 1; for (int i = 1; i < N; i ++) { f[i] = f[i-1] * (LL)i % MOD; inv[i] = mpow(f[i], MOD-2); } } int main() { init(); scanf("%s", s+1); int n = strlen(s+1); for (int i = 1; i <= n; i ++) { for (int j = 0; j < 26; j ++) { cnt[i][j] = cnt[i-1][j] + (s[i] == 'a'+j); } } //printf("%d\n", cnt[4][0]); scanf("%d", &q); while (q --) { int l, r; scanf("%d %d", &l, &r); vector even, odd; even.clear(); odd.clear(); int count = 0; for (int i = 0; i < 26; i ++) { even.push_back( (cnt[r][i] - cnt[l-1][i]) ); if ((cnt[r][i] - cnt[l-1][i]) % 2 == 1) { count ++; } } if (count == 0) count ++; LL sum = 0; for (int i = 0; i < even.size(); i ++) sum += even[i] / 2; //printf("%lld\n", sum); LL ans = f[sum]; for (int i = 0; i < even.size(); i ++) { ans = ans * inv[even[i]/2] % MOD; } printf("%lld\n", ans * count % MOD); } }