#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<cctype>
#include <iomanip>
#include <string>
#include <sstream>
#include <functional>
#include <numeric>
#include <stack>
#include <climits>
#include <float.h>
#include<unordered_map>
#include <bitset>
#include <tuple>

using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>=    b;i--)
#define sz(a) ((int)a.size())
#define all(c) c.begin(), c.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
#define dbg(x) cerr << (#x) << " --> " << (x) << endl
#define sz(a) ((int)a.size())
#define endl '\n' 

//#define fast ios_base::sync_with_stdio(0);cin.tie(0) ; 
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef long double ld;

int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); }

ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

ll poww(ll a, ll b) {
	if (b == 0) return 1;
	ll tmp = poww(a, b / 2);
	return (b & 1 ? a * tmp * tmp : tmp * tmp);
}

string itos(ll i) { string s = ""; 	while (i) { s += char(i % 10 + '0'); i /= 10; } reverse(all(s));  return s; }

ll stoi(string &s) { ll tot = 0; for (int i = (int)s.length() - 1, j = 1; i >= 0; i--, j *= 10) { tot += j * (s[i] + '0'); }  return tot; }

int months[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

using namespace std;


void tt() {
#ifndef online	_judge
	freopen("test.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
}



int mod = 1e9 + 7;

const int MAX = 1e5 + 10;
ll fact[MAX], ifact[MAX];

int pre[26][MAX];

int n;

map<int, int> mpp;
set<int> od, ev;




ll pwmod(ll num, ll pow) {

	if (pow == 0) { return 1; }

	ll x = 1ll * pwmod(num, pow / 2) % mod; ;

	ll res = 1ll * x % mod * x % mod;

	if (pow & 1) res = res * num % mod;

	return res;

}

int inv(int num) {


	return pwmod(num, mod - 2) % mod; ;
}

int main() {

	///tt(); 

	mod = 1e9 + 7;
	string s;
	cin >> s;

		
	n = (int)s.length();

	s = "#" + s;


	for (int i = 1; i <= n; i++) {

		for (int j = 0; j < 26; j++) pre[j][i] = pre[j][i - 1] + (j == (s[i] - 'a'));

	}

	

	fact[0] = 1;  //setting this to fact[0] =0 , solves the problem.
	for (int i = 1; i <= 1e5 + 10; i++) fact[i] = 1ll * i * fact[i - 1] % mod;

	

	
	for (int i = 0; i <= 1e5 + 10; i++) ifact[i] = inv(fact[i]);

	
	int q;
	cin >> q;

	while (q--) {

		mpp.clear();
		ev.clear();
		od.clear();
		int l, r;
		cin >> l >> r;

		
		for (int i = 0; i < 26; i++) {

			int cnt = pre[i][r] - pre[i][l - 1];

			if (cnt > 0) {

				if (cnt & 1) {
					
					od.insert(i);
					mpp[i] = cnt; ;

				}

				else {

					ev.insert(i);
					mpp[i] = cnt; ;
				}

		
			}
		
		}

	
		int len = 0;

		

		for (auto t : ev) len += mpp[t] / 2;
		for (auto t : od) len += mpp[t] / 2;
	
		ll ans = fact[len];


	
		ans %= mod;

		for (auto t : ev) {

			int x = mpp[t] / 2;

			ans = ans * ifact[x] % mod;
		}

		for (auto t : od) {

			int x = mpp[t] / 2; ;

			ans = ans * ifact[x] % mod;
	
		}

		
		int ocnt = (int)od.size(); 

		if (ocnt) ans = ans * ocnt % mod;

		cout << ans << endl;

	}



	return  0;;


}