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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long int inf = 1e14;
int mod = 1e9 + 7;
char en = '\n';
long long int abs1(long long int x) {
  if (x < 0) return -x;
  return x;
}
long long int power(long long int x, long long int n, long long int mod) {
  long long int res = 1;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
long long int fact[100005], ifact[100005];
long long int dp[100005][53];
long long int freq1[100005];
long long int convert(char c) {
  if (c >= 'a' && c <= 'z') return c - 'a' + 1;
  return 26 + c - 'A' + 1;
}
long long int res[53][53];
long long int tempDp[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  fact[0] = ifact[0] = 1;
  for (long long int i = 1; i < 100005; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    ifact[i] = power(fact[i], mod - 2, mod);
  }
  memset(dp, 0, sizeof(dp));
  long long int n;
  string s;
  cin >> s;
  n = s.length();
  long long int constant = 1;
  constant = fact[n / 2] * fact[n / 2] % mod;
  for (char c : s) {
    freq1[convert(c)]++;
  }
  for (long long int i = 1; i <= 52; i++) {
    constant *= ifact[freq1[i]];
    constant %= mod;
  }
  for (long long int j = 0; j <= 52; j++) dp[0][j] = 1;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 0; j <= 52; j++) {
      if (j != 0) dp[i][j] = dp[i][j - 1];
      if (!freq1[j]) continue;
      if (freq1[j] > i) continue;
      if (j != 0) dp[i][j] += dp[i - freq1[j]][j - 1] - mod;
      if (dp[i][j] < 0) dp[i][j] += mod;
    }
  }
  for (long long int i = 1; i <= 52; i++) {
    if (!freq1[i]) continue;
    for (long long int i = 0; i <= n; i++) tempDp[i] = dp[i][52];
    for (long long int j = freq1[i]; j <= n; j++) {
      tempDp[j] -= tempDp[j - freq1[i]];
      if (tempDp[j] < 0) tempDp[j] += mod;
    }
    res[i][i] = (2 * tempDp[n / 2]) % mod;
    for (long long int j = 1; j <= 52; j++) {
      if (!freq1[j]) continue;
      if (j == i) continue;
      for (long long int k = freq1[j]; k <= n; k++) {
        tempDp[k] -= tempDp[k - freq1[j]];
        if (tempDp[k] < 0) tempDp[k] += mod;
      }
      res[i][j] = (tempDp[n / 2] * 2) % mod;
      for (long long int k = n; k >= freq1[j]; k--) {
        tempDp[k] += tempDp[k - freq1[j]] - mod;
        if (tempDp[k] < 0) tempDp[k] += mod;
      }
    }
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int x, y;
    cin >> x >> y;
    x--, y--;
    cout << (constant * res[convert(s[x])][convert(s[y])] % mod) << en;
  }
  return 0;
}