#include using ll = long long; using ull = unsigned long long; using std::cout; using std::cerr; using std::cin; inline void write(std::ostream &) {} template inline void write(std::ostream &s, T t) { s << t; } inline void writeF(std::ostream &s, const char *format) { s << format; } template inline void write(std::ostream &s, T t, Args... args) { s << t << ' ', write(s, args...); } template void writeF(std::ostream &s, const char *format, T t, Args... args) { while (*format != '%' && *format) s.put(*format++); if (*format++ == '\0') return; s << t, writeF(s, format, args...); } #define print(...) write(cout, __VA_ARGS__) #define error(...) write(cerr, __VA_ARGS__) #define printF(fmt, ...) writeF(cout, fmt, __VA_ARGS__) #define errorF(fmt, ...) writeF(cerr, fmt, __VA_ARGS__) template inline void println(Args... args) { write(cout, args...), cout << '\n'; } template inline void errorln(Args... args) { write(cerr, args...), cerr << '\n'; } template class RangeSum { std::vector cumulative; public: RangeSum(const std::vector &arr) { T sum = 0; for (auto &elem : arr) { sum += elem; cumulative.push_back(sum); } } T get(int left, int right) { if (left > right || right < 0) return 0; if (left <= 0) return cumulative[right]; return cumulative[right] - cumulative[left - 1]; } }; template class ModRing { inline ll mod(ll x) { return (x + MAX) % MAX; } public: ll val; ModRing(ll x = 0) : val(x) {} ModRing operator+(const ModRing &b) { return mod(val + b.val); } ModRing operator-(const ModRing &b) { return mod(val - b.val); } ModRing operator*(const ModRing &b) { return mod(val * b.val); } ModRing operator/(const ModRing &b) { return b.inv() * val; } bool operator!=(const ModRing &b) { return mod(val) != mod(b.val); } ModRing operator+=(const ModRing &b) { return val = mod(val + b.val); } ModRing operator*=(const ModRing &b) { return val = mod(val * b.val); } ModRing inv() const { return pow(MAX - 2); } ModRing pow(ll p) const { if (p == 1) return this->val; if (p == 0) return 1; auto ans = this->pow(p / 2); ans *= ans; if (p % 2 == 1) ans *= this->val; return ans; } }; template std::ostream &operator<<(std::ostream &os, const ModRing &obj) { return os << obj.val; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::vector> factorial; factorial.push_back(1); factorial.push_back(1); for (int i = 2; i <= 100010; ++i) { factorial.push_back(factorial.back() * i); } std::string str; cin >> str; std::array, 26> data; for (auto &elem : str) { for (int i = 0; i < 26; ++i) { data[i].push_back(('a' + i == elem) ? 1 : 0); } } std::vector> freq; for (int i = 0; i < 26; ++i) freq.emplace_back(data[i]); int Q, l, r; cin >> Q; for (int q = 0; q < Q; ++q) { cin >> l >> r; l--, r--; std::array c; for (int i = 0; i < 26; ++i) c[i] = freq[i].get(l, r); ll total = 0, odd = 0; for (int i = 0; i < 26; ++i) { total += c[i] / 2; if (c[i] % 2 != 0) odd++; } ModRing<1000000007> ans = factorial[total]; for (int i = 0; i < 26; ++i) ans = ans / factorial[c[i] / 2]; if (odd != 0) ans *= odd; println(ans); } return 0; } /*** abab 1 1 4 week 2 1 4 2 3 ***/