#include "bits/stdc++.h" using namespace std; template class umod_t{ private: long long number; public: umod_t(): number(0ll){} umod_t(long long value){ value %= mod; if(value < 0) value += mod; number = value; } umod_t & operator += (umod_t other){ number += other.number; if(number >= mod) number -= mod; return * this; } umod_t & operator -= (umod_t other){ number -= other.number; if(number < 0) number += mod; return * this; } umod_t & operator *= (umod_t other){ number = number * other.number % mod; return * this; } umod_t & operator /= (umod_t other){ return * this *= other.inverse(); } umod_t operator + (umod_t other) const { return umod_t(*this) += other; } umod_t operator - (umod_t other) const { return umod_t(*this) -= other; } umod_t operator * (umod_t other) const { return umod_t(*this) *= other; } umod_t operator / (umod_t other) const { return umod_t(*this) /= other; } bool operator < (umod_t other) const { return number < other.number; } bool operator > (umod_t other) const { return number > other.number; } bool operator <= (umod_t other) const { return number <= other.number; } bool operator >= (umod_t other) const { return number >= other.number; } bool operator == (umod_t other) const { return number == other.number; } bool operator != (umod_t other) const { return number != other.number; } umod_t inverse() const { long long a = number, b = mod, u = 1, v = 0; while(b){ long long t = a/b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if(u < 0) u += mod; return u; } long long getNumber(){ return number; } }; const int maxn = 111111; int occ[26][maxn], cnt[26]; umod_t<> fat[maxn]; int main(){ fat[0] = 1; for(int e = 1; e < maxn; e++) fat[e] = fat[e-1] * e; string s; cin >> s; for(int e = 1; e <= s.size(); e++) occ[s[e-1] - 'a'][e]++; int len = s.size(); for(int e = 0; e < 26; e++){ for(int f = 1; f <= len; f++) occ[e][f] += occ[e][f-1]; } int q; scanf("%d", &q); while(q--){ int l, r; scanf("%d %d", &l, &r); for(int e = 0; e < 26; e++) cnt[e] = occ[e][r] - occ[e][l-1]; int max_len = 0, sum = 0; for(int e = 0; e < 26; e++) sum += 2 * (cnt[e] / 2); max_len = sum; for(int e = 0; e < 26; e++){ if(cnt[e] % 2 == 1) max_len = sum + 1; } umod_t<> ans = 0; if(max_len == sum){ umod_t<> cur = fat[max_len / 2]; for(int e = 0; e < 26; e++) cur /= fat[cnt[e]/2]; printf("%lld\n", cur.getNumber()); } else { umod_t<> cur = fat[max_len / 2], ans = 0; for(int e = 0; e < 26; e++) cur /= fat[cnt[e]/2]; for(int e = 0; e < 26; e++){ if(cnt[e]%2 == 1) ans += cur; } printf("%lld\n", ans.getNumber()); } } return 0; }