//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = (int)1e5 + 228;
const int MOD = (int)1e9 + 7;

using namespace std;

int n, cnt[N][50];
string s;
ll f[N];

ll binpow(ll a, ll k)
{	
	ll res = 1;
	while(k)
	{
		if (k & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		k >>= 1;
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	cout.tie();		

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	cin >> s;
	n = (int)s.size();
	s = '#' + s;
	f[0] = 1;
	forn(i, n)
	{
		f[i] = f[i - 1] * i % MOD;
		for (int ch = 'a'; ch <= 'z'; ch++)
			cnt[i][ch - 'a'] = cnt[i - 1][ch - 'a'];
		cnt[i][s[i] - 'a']++;
	}
	int q;
	cin >> q;
	forn(i, q)
	{
		int l, r;
		cin >> l >> r;
		int cur = 0;
		ll res = 1;
		int len = r - l + 1;
		for (int ch = 'a'; ch <= 'z'; ch++)
		{
			int k = cnt[r][ch - 'a'] - cnt[l - 1][ch - 'a'];
			res = res * binpow(f[k / 2], MOD - 2) % MOD;
			if (k & 1)
				cur++, len--;
		}
		res = res * f[len / 2] % MOD;
		if (cur == 0)
			cout << res << endl;
		else
			cout << res * cur % MOD << endl;
	}

	return 0;
}