#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define cin_desync()                      \
	do {                                  \
		ios_base::sync_with_stdio(false); \
		cin.tie(0);                       \
	} while (0)                           \

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int max_N = 1e5 + 10;
const int max_A = 30;
const ll mod = 1e9 + 7;

int store[max_A][max_N];
ll fact[max_N], finv[max_N];

ll modexp(ll a, ll b);
ll query(int L, int R);

int main()
{
	cin_desync();

	fact[0] = 1;
	finv[0] = 1;
	for (int i = 1; i < max_N; ++i) {
		fact[i] = (fact[i - 1] * i) % mod;
		finv[i] = modexp(fact[i], mod - 2);
	}

	string S;
	cin >> S;
	int N = S.length();
	for (int i = 1; i <= N; ++i) {
		for (int c = 0; c < 26; ++c) {
			store[c][i] = store[c][i - 1];
		}
		store[S[i - 1] - 'a'][i]++;
	}


	int Q;
	cin >> Q;
	while(Q--) {
		int L, R;
		cin >> L >> R;
		cout << query(L, R) << '\n';
	}
}

ll query(int L, int R)
{
	int odd_count = 0;
	int even_tot = 0; ll ans = 1;
	for (int c = 0; c < 26; ++c) {
		int count = store[c][R] - store[c][L - 1];
		int ec = count / 2;
		odd_count += (count % 2);
		ans *= finv[ec];
		ans %= mod;
		even_tot += ec;
	}

	ans *= fact[even_tot];
	ans %= mod;

	if (odd_count) {
		ans *= odd_count;
	}
	return ans % mod;
}

ll modexp(ll a, ll b)
{
	ll ans = 1, res = a;
	for (; b; b >>= 1) {
		if (b & 1) {
			ans *= res;
			ans %= mod;
		}
		res *= res;
		res %= mod;
	}

	return ans;
}