#include using namespace std; #define SHORT_INF 0x3f3f #define INT_INF 0x3f3f3f3f #define LL_INF 0x3f3f3f3f3f3f3f3f #define D_INF numeric_limits::infinity() #define pb push_back #define mp make_pair #define l(x) ((x) << 1) #define r(x) ((x) << 1 | 1) #define m(x, y) ((x) + ((y) - (x)) / 2) #define MIN(a, b) ((a) = min((a), (b))) #define MAX(a, b) ((a) = max((a), (b))) #define f first #define s second #define ri(x) scanf("%d", &x) #define rll(x) scanf("%lld", &x) #define rllu(x) scanf("%llu", &x) #define rf(x) scanf("%f", &x) #define rd(x) scanf("%lf", &x) #define rld(x) scanf("%Lf", &x) #define rc(x) scanf(" %c", &x) #define sc(x) do { scanf("%c", &x); } while (isspace(x)) #define rs(x) scanf("%s", x) #define For(i, a, b) for (int i = (a); i < (b); i++) #define FOR(i, b) For(i, 0, b) #define Forit(i, c) for (auto i = (c).begin(); i != (c).end(); i++) #define Rev(i, a, b) for (int i = (a); i > (b); i--) #define REV(i, a) Rev(i, a, -1) #define Revit(i, c) for (auto i = (c).rbegin(); i != (c).rend(); i++) #define set0(a) memset((a), 0, sizeof(a)) #define Fill(a, x, n) FOR(_, n) (a)[_] = (x) #define Fill2(a, x, n, m) FOR(_, n) FOR(__, m) (a)[_][__] = (x) #define Fill3(a, x, n, m, p) FOR(_, n) FOR(__, m) FOR(___, p) (a)[_][__][___] = (x) #define randi(a, b) (rand() % ((b) - (a) + 1) + (a)) #define sz(a) ((int) (a).size()) #define len(a) ((int) (a).length()) typedef long long ll; typedef unsigned long long llu; typedef long double ld; #define uset unordered_set #define umap unordered_map #define pq priority_queue typedef pair pii; typedef pair pdd; typedef pair pll; typedef pair pill; typedef pair plli; typedef map mii; typedef map mill; typedef map mlli; typedef map mll; typedef umap umii; typedef umap umill; typedef umap umlli; typedef umap umll; template using minpq = pq, greater>; template using maxpq = pq, less>; #define debug(fmt, x) fprintf(stderr, "%d::%s = " fmt, __LINE__, #x, (x)); fflush(stderr) #define debug2(x) cerr << __LINE__ << "::" << #x << " = " << (x) << '\n' << flush #define debugva(fmt, ...) fprintf(stderr, "%d::%s = " fmt, __LINE__, #__VA_ARGS__, __VA_ARGS__); fflush(stderr) #define debugarr(fmt, x, a, b) fprintf(stderr, "%d::%s = {", __LINE__, #x); For(_, a, b) { if (_ != (a)) { fprintf(stderr, ", "); } fprintf(stderr, fmt, (x)[_]); } fprintf(stderr, "}\n"); fflush(stderr) #define debugarr2(x, a, b) cerr << __LINE__ << "::" << #x << " = {"; For(_, a, b) { if (_ != (a)) { cerr << ", "; } cerr << (x)[_]; } cerr << "}\n" << flush template struct pair_hash {size_t operator ()(const pair &p) const {return 31 * hash {}(p.first) + hash {}(p.second);}}; #define MAXS 100010 #define MOD 1000000007 string S; int Q, L, R, freq[26][MAXS]; ll fact[MAXS]; long long pow3(long long base, long long pow, long long mod) { if (pow == 0) return 1; if (pow == 1) return base; if (pow % 2 == 0) return pow3(base * base % mod, pow / 2, mod); return base * pow3(base * base % mod, pow / 2, mod) % mod; } long long divMod(long long i, long long j, long long p) { return i * pow3(j, p - 2, p) % p; } int main() { cin.sync_with_stdio(0); cin.tie(0); cin >> S; FOR(i, len(S)) freq[S[i] - 'a'][i + 1]++; fact[0] = 1; For(i, 1, len(S) + 2) fact[i] = (fact[i - 1] * i) % MOD; FOR(i, 26) For(j, 1, len(S) + 1) freq[i][j] += freq[i][j - 1]; cin >> Q; FOR(i, Q) { cin >> L >> R; int single = 0, dual = 0; ll rep = 1; FOR(i, 26) { int x = freq[i][R] - freq[i][L - 1]; if (x % 2 == 1) single++; dual += x / 2; rep = (rep * fact[x / 2]) % MOD; } // debug2(dual); ll num = fact[dual]; single %= MOD; if (single == 0) single = 1; cout << (single * divMod(num, rep, MOD)) % MOD << "\n"; } return 0; }