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;
const int N = 1e5;
const int S = 52;
const int P = 1e9 + 7;
char str[N + 3];
int a[N + 3];
int num[S + 3];
long long dp1[S + 3][N + 3], dp2[S + 3][N + 3], g[N + 3];
long long fact[N + 3], finv[N + 3];
long long ans[S + 3][S + 3];
int n, q;
long long quickpow(long long x, long long y) {
  long long cur = x, ret = 1ll;
  for (int i = 0; y; i++) {
    if (y & (1ll << i)) {
      y -= (1ll << i);
      ret = ret * cur % P;
    }
    cur = cur * cur % P;
  }
  return ret;
}
long long mulinv(long long x) { return finv[x] * fact[x - 1] % P; }
long long comb(long long x, long long y) {
  return x < 0 || y < 0 || x < y ? 0ll
                                 : fact[x] * finv[y] % P * finv[x - y] % P;
}
long long combinv(long long x, long long y) {
  return x < 0 || y < 0 || x < y ? 0ll
                                 : finv[x] * finv[y] % P * fact[x - y] % P;
}
int decode(char ch) {
  if (ch >= 'A' && ch <= 'Z') {
    return ch - 'A' + 27;
  } else if (ch >= 'a' && ch <= 'z') {
    return ch - 'a' + 1;
  }
}
int main() {
  fact[0] = 1ll;
  for (int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i % P;
  finv[N] = quickpow(fact[N], P - 2);
  for (int i = N - 1; i >= 0; i--) finv[i] = finv[i + 1] * (i + 1) % P;
  scanf("%s", str + 1);
  n = strlen(str + 1);
  scanf("%d", &q);
  for (int i = 1; i <= n; i++) a[i] = decode(str[i]);
  for (int i = 1; i <= n; i++) num[a[i]]++;
  int sum = 0;
  dp1[0][0] = 1ll;
  long long tot = fact[n >> 1] * fact[n >> 1] % P;
  for (int i = 1; i <= S; i++) tot = tot * finv[num[i]] % P;
  for (int j = 1; j <= S; j++) {
    int anow = num[j];
    if (anow == 0) {
      for (int k = 0; k <= n; k++) dp1[j][k] = dp1[j - 1][k];
      continue;
    }
    for (int k = 0; k <= n; k++) {
      dp1[j][k] = dp1[j - 1][k];
      if (k >= num[j]) {
        dp1[j][k] = (dp1[j][k] + dp1[j - 1][k - num[j]]) % P;
      }
    }
    sum += anow;
  }
  for (int i = 1; i <= S; i++) ans[i][i] = dp1[S][n >> 1];
  for (int i = 1; i <= S; i++) {
    for (int j = i + 1; j <= S; j++) {
      ans[i][j] = 0ll;
      int anow = num[i] + num[j];
      if (anow > (n >> 1)) {
        ans[i][j] = 0ll;
        continue;
      }
      if (num[i] == 0 || num[j] == 0) {
        ans[i][j] = ans[i][i];
        continue;
      }
      for (int k = 0; k <= n; k++) {
        g[k] = dp1[S][k];
      }
      for (int k = 0; k <= n; k++) {
        g[k] = (g[k] - (k < num[i] ? 0ll : g[k - num[i]]) + P) % P;
      }
      for (int k = 0; k <= n; k++) {
        g[k] = (g[k] - (k < num[j] ? 0ll : g[k - num[j]]) + P) % P;
      }
      ans[i][j] = (g[(n >> 1) - num[i] - num[j]] + g[(n >> 1)]) % P;
    }
  }
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = a[x];
    y = a[y];
    if (x > y) swap(x, y);
    printf("%I64d\n", ans[x][y] * tot % P);
  }
  return 0;
}