#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MOD 1000000007

LL cnt[26][100001];
LL fact[100005];
LL invfact[100005];
char str[100005];
LL mod_pow(LL x, LL n) {
	LL res = 1LL;
	while (n > 0) {
		if (n & 1) res = res * x % MOD;
		x = x*x % MOD;
		n >>= 1;
	}
	return res;
}

LL mod_inv(LL x) {
	return mod_pow(x, MOD - 2) % MOD;
}

int main() {
	fact[0] = 1;
	for (int i = 1; i < 100005; i++) fact[i] = (fact[i - 1] * i) % MOD;
	for (int i = 0; i < 100005; i++) invfact[i] = mod_inv(fact[i]);
	scanf("%s", &str);
	int n = strlen(str);
	for (int i = 0; i < n; i++) {
		for (int c = 'a'; c <= 'z'; c++) {
			cnt[c - 'a'][i + 1] = cnt[c - 'a'][i] + (c == str[i]);
		}
	}
	int Q;
	scanf("%d", &Q);
	REP(q, Q) {
		int l, r, s=0, odd = 0;
		scanf("%d%d", &l, &r);
		VLL vcnt = VLL(26, 0);
		for (int c = 'a'; c <= 'z'; c++) {
			vcnt[c - 'a'] = cnt[c - 'a'][r] - cnt[c - 'a'][l - 1];
			s += (vcnt[c - 'a']) / 2;
			odd += (vcnt[c - 'a']) % 2;
			vcnt[c - 'a'] /= 2;
		}
		if (odd == 0)odd = 1;
		LL ans = (fact[s] * odd)%MOD;
		for (int i = 0; i < 26; i++) ans = (ans*invfact[vcnt[i]]) % MOD;
		printf("%lld\n", ans);
	}
	return 0;
}