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 mod = 1000000007;
long long mul[1000010], inv[1000010];
int num[100];
long long A(int n, int m) {
  if (m > n) return 0;
  if (m == 0) return 1;
  long long t1 = mul[n];
  long long t2 = inv[n - m];
  return ((t1 % mod) * (t2 % mod)) % mod;
}
long long C(int n, int m) {
  if (m > n) return 0;
  if (m == n) return 1;
  if (m == 0) return 1;
  long long t1 = mul[n];
  long long t2 = inv[n - m] * inv[m];
  return ((t1 % mod) * (t2 % mod)) % mod;
}
long long pw(long long a, int b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = (ret * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ret;
}
long long dpp[200000], dp[200000];
long long res[200][200];
int id(char c) {
  if (c <= 'z' && c >= 'a') return c - 'a';
  return c - 'A' + 26;
}
void init() {
  mul[0] = 1;
  inv[0] = 1;
  mul[1] = 1;
  inv[1] = 1;
  for (int i = 2; i <= 100000; ++i) {
    mul[i] = (mul[i - 1] * i) % mod;
    inv[i] = (inv[i - 1] * pw(i, mod - 2)) % mod;
  }
}
int main() {
  string s;
  cin >> s;
  init();
  memset(num, 0, sizeof(num));
  int len = s.size();
  for (int i = 0; i < len; ++i) {
    num[id(s[i])]++;
  }
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int k = 0; k < 52; ++k) {
    if (num[k] == 0) continue;
    for (int j = len / 2; j >= 0; --j) {
      dp[j + num[k]] = (dp[j] + dp[j + num[k]]) % mod;
    }
  }
  for (int i = 0; i < 52; ++i) {
    if (num[i] == 0) continue;
    for (int j = 0; j < 52; ++j) {
      if (num[j] == 0) continue;
      for (int ii = 0; ii <= len / 2; ++ii) {
        dpp[ii] = dp[ii];
      }
      for (int ii = num[i]; ii <= len / 2; ++ii) {
        dpp[ii] = (dpp[ii] - dpp[ii - num[i]] + mod) % mod;
      }
      if (i != j) {
        for (int ii = num[j]; ii <= len / 2; ++ii) {
          dpp[ii] = (dpp[ii] - dpp[ii - num[j]] + mod) % mod;
        }
        res[i][j] = dpp[len / 2 - num[i] - num[j]];
      } else {
        res[i][j] = dpp[len / 2 - num[i]];
      }
    }
  }
  long long frac = (mul[len / 2] * mul[len / 2]) % mod;
  for (int i = 0; i < 52; ++i) {
    if (num[i] == 0) continue;
    frac = (frac * inv[num[i]]) % mod;
  }
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    int ii = id(s[x]);
    int jj = id(s[y]);
    long long ans = (2 * res[ii][jj] * frac) % mod;
    cout << ans << endl;
  }
}