#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

#define MOD 1000000007

template<class T>
T pow(T x, int power, T mod)
{
	T res = 1;

	for(T b=x; power; power>>=1)
	{
		if(power&1)
			res = (res * b) % mod;
		b = (b * b) % mod;
	}

	return res;
}

ll inv(ll x)
{
	ll y = pow(x, MOD-2, (ll)MOD);
	//ASSERT(x*y%MOD == 1);
	return y;
}

int s[32][100111] ={0};
int fact[100111];
int ifact[100111];

int main()
{
	string str;
	cin >> str;
	int n = str.size();
	
	for(int l=0; l<26; ++l)
		for(int i=0; i<n; ++i)
			s[l][i+1] = (str[i] == 'a'+l ? 1 : 0) + s[l][i];
	
	fact[0] = ifact[0] = 1;
	for(int i=1; i<=n; ++i)
	{
		fact[i] = (i*1LL*fact[i-1]) % MOD;
		ifact[i] = (int)inv(fact[i]);
	}

	int q;
	cin >> q;
	for(int i=0; i<q; ++i)
	{
		int l, r;
		cin >> l >> r;
		int sl[26] = {0};
		int tot = 0, nodd = 0;
		for(int j=0; j<26; ++j)
		{
			sl[j] = s[j][r] - s[j][l-1];
			if(sl[j]%2)
				nodd += 1;
			sl[j] /= 2;
			//sl[j] *= 2;
			tot += sl[j];
		}
		ll ans = max(1,nodd);
		ans = (ans*fact[tot])%MOD;
		for(int j=0; j<26; ++j)
			ans = (ans*ifact[sl[j]])%MOD;
		cout << ans << "\n";
	}

	return 0;
}