#include using namespace std; #define ll long long #define f(i, x, n) for(int i = x; i < (int)(n); ++i) int const N = 100000; char s[N + 1]; vector qu[N]; bool vis[N]; int fr[N][26], fr0[26], md = 1e9 + 7, fc[N + 1], inv[N + 1], fcin[N + 1]; int ch(int a, int b) { return (ll)fc[a] * fcin[b] % md * fcin[a - b] % md; } int main(){ fc[0] = 1; f(i, 1, N + 1)fc[i] = (ll)fc[i - 1] * i % md; inv[1] = 1; f(i, 2, N + 1)inv[i] = md - md / i * (ll)inv[md % i] % md; fcin[0] = 1; f(i, 1, N + 1)fcin[i] = (ll)fcin[i - 1] * inv[i] % md; scanf("%s", s); int n = strlen(s); int q; scanf("%d", &q); f(i, 0, q){ int l, r; scanf("%d%d", &l, &r); if (l == 1)vis[i] = true; else qu[l - 2].push_back(i); qu[r - 1].push_back(i); } f(i, 0, n){ ++fr0[s[i] - 'a']; f(j, 0, qu[i].size()){ int v = qu[i][j]; if (vis[v])f(k, 0, 26)fr[v][k] += fr0[k]; else { vis[v] = true; f(k, 0, 26)fr[v][k] -= fr0[k]; } } } f(i, 0, q){ int o = 0, an = 1, ln = 0; f(j, 0, 26)ln += fr[i][j] >> 1; f(j, 0, 26){ if (fr[i][j] & 1)++o; an = (ll)an * ch(ln, fr[i][j] >> 1) % md; ln -= fr[i][j] >> 1; } if (o)an = (ll)an * o % md; printf("%d\n", an); } }