#include <bits/stdc++.h>

using namespace std;
#define ll long long

const ll mod = 1000000007LL;

ll inv(ll base, ll pow) {
	if (pow == 0LL) return 1LL;
	if (pow == 1LL) return base;
	if (pow %2 == 0LL) {
		ll temp = inv(base, pow/2);
		temp = (temp*temp)%mod;
		return temp;
	}
	else {
		ll temp = inv(base, pow-1);
		temp = (temp*base)%mod;
		return temp;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	int q;
	cin >> q;
	int l, r;
	int n = s.length();
	int ct[n+1][26];
	ll facts[100010];
	ll invfacts[100010];
	facts[0] = 1;
	invfacts[0] = 1;
	for (int i = 1; i <= 100000; i++) {
		facts[i] = (facts[i-1]*(i+0LL))%mod;
		invfacts[i] = inv(facts[i], mod-2);
	}
	for (int i = 0; i < 26; i++) {
		ct[i][0] = 0;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 26; j++) {
			ct[i][j] = ct[i-1][j];
		}
		ct[i][s[i-1]-'a']++;
	}
	for (int i = 0; i < q; i++) {
		cin >> l >> r;
		ll ans = 0LL;
		int tpairs = 0;
		for (int j = 0; j < 26; j++) {
			int cur = ct[r][j]-ct[l-1][j];
			tpairs += cur/2;
		}
		ans = facts[tpairs];
		for (int j = 0; j < 26; j++) {
			int cur = ct[r][j]-ct[l-1][j];
			cur = cur/2;
			ans = (ans*invfacts[cur])%mod;
		}
		int op = 0;
		for (int j = 0; j < 26; j++) {
			int cur = ct[r][j]-ct[l-1][j];
			if (cur%2 == 1) {
				op++;
			}
		}
		if (op > 0) {
			ans = (ans*(op+0LL))%mod;
		}
		if (tpairs == 0LL) ans = op;
		cout << ans << endl;
	}
	cin >> l;

}