Problem: There is a colony of villains with several holes aligned in a row, where each hole contains exactly one villain.

Each colony arrangement can be expressed as a string of even length, where the i-th character of the string represents the type of villain in the i-th hole. 

Iron Man can destroy a colony only if the colony arrangement is such that all villains of a certain type either live in the first half of the colony or in the second half of the colony.

His assistant Jarvis has a special power. It can swap villains of any two holes, i.e. swap any two characters in the string; he can do this operation any number of times.

Now Iron Man asks Jarvis q questions. In each question, he gives Jarvis two numbers x and y. Jarvis has to tell Iron Man the number of distinct colony arrangements he can create from the original one using his powers such that all villains having the same type as those originally living in x-th hole or y-th hole live in the same half and the Iron Man can destroy that colony arrangement.

Two colony arrangements are considered to be different if there exists a hole such that different types of villains are present in that hole in the arrangements.

Input

The first line contains a string s (2 ≤ |s| ≤ 10^{5}), representing the initial colony arrangement. String s can have both lowercase and uppercase English letters and its length is even.

The second line contains a single integer q (1 ≤ q ≤ 10^{5}) — the number of questions.

The i-th of the next q lines contains two integers x_i and y_i (1 ≤ x_i, y_i ≤ |s|, x_i ≠ y_i) — the two numbers given to the Jarvis for the i-th question.

Output

For each question output the number of arrangements possible modulo 10^9+7.

Examples

Input


abba
2
1 4
1 2


Output


2
0


Input


AAaa
2
1 2
1 3


Output


2
0


Input


abcd
1
1 3


Output


8

Note

Consider the first example. For the first question, the possible arrangements are "aabb" and "bbaa", and for the second question, index 1 contains 'a' and index 2 contains 'b' and there is no valid arrangement in which all 'a' and 'b' are in the same half.

Solution (in JAVA):

Solution:
var s = readline();
var qq = readline().split(" ").map(function(x) { return parseInt(x); })[0];

var cnt = Array(52).fill(0);

const ALPHABET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
get_ind = function (c) {
 	return ALPHABET.indexOf(c);
};

const MOD = 1000000007;

mulmod = function(a, b) {
  if (a < b) a = b + (b=a, 0);   // swap
  var x = 0, y = a % MOD;
  while (b) {
    if (b & 1) {
    	x += y;
    	if (x >= MOD) x -= MOD;
    }
    y <<= 1;
    if (y >= MOD) y -= MOD;
    b >>= 1;
  }
  return x;
}

find_deg = function(x, deg) {
	var b = 1, a = x % MOD;
	while (deg) {
		if (deg & 1) b = mulmod(b, a);
		deg >>= 1;
		if (deg > 0) a = mulmod(a, a);
	}
	return b % MOD;
};

find_rev = function(x) {
	return find_deg(x, MOD-2);   // MOD is prime, so MOD-2 is correct Phi-1 value
};

var fakt = Array(s.length+1).fill(0);
var rev_fakt = Array(s.length+1).fill(0);

cnk = function(n, k) {
	return mulmod(mulmod(fakt[n], rev_fakt[k]), rev_fakt[n-k]);
}

var half = Math.floor(s.length / 2);
var dp = Array(half + 1).fill(0);

solve = function(wth) {
	var sum_wth = 0;
	for (var i=0; i<wth.length; i++) sum_wth += cnt[wth[i]];
	if (sum_wth > half)
		return 0;

	var dp_copy = dp.slice();
	for (var i=0; i<wth.length; i++)
		for (var j=0; j+cnt[wth[i]] <= half; j++)
			if (dp_copy[j] > 0)
				dp_copy[j+cnt[wth[i]]] = (dp_copy[j+cnt[wth[i]]] - dp_copy[j] + MOD) % MOD;

	return dp_copy[half];
}

for (var i=0; i<s.length; i++)
	cnt[get_ind(s[i])]++;

var ans = 0;

var inv = Array(s.length+1).fill(0);
inv[1] = 1;
for (var i=2; i<=s.length; i++) inv[i] = mulmod(inv[MOD % i], (MOD - Math.floor(MOD/i)));
fakt[0] = 1; fakt[1] = 1;
rev_fakt[0] = 1; rev_fakt[1] = 1;
for (var i=2; i<=s.length; i++) {
	fakt[i] = mulmod(fakt[i-1],i);
	rev_fakt[i] = mulmod(rev_fakt[i-1], inv[i]);
}

var glob_rev = 1;
for (var i=0; i<52; i++)
	if (cnt[i] > 0)
		glob_rev = mulmod(rev_fakt[cnt[i]],glob_rev);

for (var j=0; j<=half; j++) dp[j] = 0;
dp[0] = 1;
for (var i=0; i<52; i++)
	if (cnt[i] > 0)
		for (var j=half-cnt[i]; j>=0; j--)
			if (dp[j] > 0)
				dp[j + cnt[i]] = (dp[j + cnt[i]] + dp[j]) % 1000000007;

var solve_one = Array(52).fill(-1);

var solve_two = Array(52);
for (var j=0; j<52; j++)
	if (cnt[j] > 0) {
		var tt = Array(52).fill(-1);
		solve_two[j] = tt;
	}

var ee = [];

for (var i=0; i<qq; i++) {
	var a,b;
	var numbers = readline().split(" ").map(function(x) { return parseInt(x); });
	a = numbers[0]-1;
	b = numbers[1]-1;
	var a_ind = get_ind(s[a]);
	var b_ind = get_ind(s[b]);

	var total = cnt[a_ind] + cnt[b_ind];
	if (a_ind === b_ind)
		total -= cnt[b_ind];

	if (total > half) {
		ee.push(0);
		continue;
	}

	if (a_ind > b_ind) a_ind = b_ind + (b_ind=a_ind, 0);   // swap

	if (a_ind !== b_ind) {
		if (solve_two[a_ind][b_ind] === -1) {
			var tt = [];
			tt.push(a_ind);
			tt.push(b_ind);
			solve_two[a_ind][b_ind] = solve(tt);
		}
		ans = mulmod(mulmod(cnk(half, cnt[a_ind]), cnk(half - cnt[a_ind], cnt[b_ind]))*2, fakt[half]);
		ans = mulmod(mulmod(ans, fakt[half-cnt[a_ind]-cnt[b_ind]]), (glob_rev));
		ans = mulmod(mulmod(mulmod(ans,fakt[cnt[a_ind]]), fakt[cnt[b_ind]]), solve_two[a_ind][b_ind]);
	}
	else {
		if (solve_one[a_ind] === -1) {
			var tt = [];
			tt.push(a_ind);
			solve_one[a_ind] = solve(tt);
		}
		ans = mulmod(mulmod(mulmod(mulmod(mulmod(cnk(half, cnt[a_ind]), fakt[half])*2, fakt[half-cnt[a_ind]]), glob_rev), fakt[cnt[a_ind]]), solve_one[a_ind]);
	}
	ee.push(ans);
}

print(ee.join("\n"));