#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<cctype>
#include <iomanip>
#include <string>
#include <sstream>
#include <functional>
#include <numeric>
#include <stack>
#include <climits>
#include <float.h>
#include<unordered_map>
#include <bitset>
#include <tuple>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>= b;i--)
#define sz(a) ((int)a.size())
#define all(c) c.begin(), c.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
#define dbg(x) cerr << (#x) << " --> " << (x) << endl
#define sz(a) ((int)a.size())
#define endl '\n'
//#define fast ios_base::sync_with_stdio(0);cin.tie(0) ;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef long double ld;
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll poww(ll a, ll b) {
if (b == 0) return 1;
ll tmp = poww(a, b / 2);
return (b & 1 ? a * tmp * tmp : tmp * tmp);
}
string itos(ll i) { string s = ""; while (i) { s += char(i % 10 + '0'); i /= 10; } reverse(all(s)); return s; }
ll stoi(string &s) { ll tot = 0; for (int i = (int)s.length() - 1, j = 1; i >= 0; i--, j *= 10) { tot += j * (s[i] + '0'); } return tot; }
int months[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
using namespace std;
void tt() {
#ifndef online _judge
freopen("test.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
}
int mod = 1e9 + 7;
const int MAX = 1e5 + 10;
ll fact[MAX], ifact[MAX];
int pre[26][MAX];
int n;
map<int, int> mpp;
set<int> od, ev;
ll pwmod(ll num, ll pow) {
if (pow == 0) { return 1; }
ll x = 1ll * pwmod(num, pow / 2) % mod; ;
ll res = 1ll * x % mod * x % mod;
if (pow & 1) res = res * num % mod;
return res;
}
int inv(int num) {
return pwmod(num, mod - 2) % mod; ;
}
int main() {
///tt();
mod = 1e9 + 7;
string s;
cin >> s;
n = (int)s.length();
s = "#" + s;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++) pre[j][i] = pre[j][i - 1] + (j == (s[i] - 'a'));
}
fact[0] = 1; //setting this to fact[0] =0 , solves the problem.
for (int i = 1; i <= 1e5 + 10; i++) fact[i] = 1ll * i * fact[i - 1] % mod;
for (int i = 0; i <= 1e5 + 10; i++) ifact[i] = inv(fact[i]);
int q;
cin >> q;
while (q--) {
mpp.clear();
ev.clear();
od.clear();
int l, r;
cin >> l >> r;
for (int i = 0; i < 26; i++) {
int cnt = pre[i][r] - pre[i][l - 1];
if (cnt > 0) {
if (cnt & 1) {
od.insert(i);
mpp[i] = cnt; ;
}
else {
ev.insert(i);
mpp[i] = cnt; ;
}
}
}
int len = 0;
for (auto t : ev) len += mpp[t] / 2;
for (auto t : od) len += mpp[t] / 2;
ll ans = fact[len];
ans %= mod;
for (auto t : ev) {
int x = mpp[t] / 2;
ans = ans * ifact[x] % mod;
}
for (auto t : od) {
int x = mpp[t] / 2; ;
ans = ans * ifact[x] % mod;
}
int ocnt = (int)od.size();
if (ocnt) ans = ans * ocnt % mod;
cout << ans << endl;
}
return 0;;
}
I2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y3RpbWU+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGU8Y3N0ZGlvPgojaW5jbHVkZTxzc3RyZWFtPgojaW5jbHV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