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>
struct mint {
  int n;
  mint(int n_ = 0) : n(n_) {}
};
mint operator+(mint a, mint b) {
  a.n += b.n;
  if (a.n >= 1000000007) a.n -= 1000000007;
  return a;
}
mint operator-(mint a, mint b) {
  a.n -= b.n;
  if (a.n < 0) a.n += 1000000007;
  return a;
}
mint operator*(mint a, mint b) { return (long long)a.n * b.n % 1000000007; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
mint F[100001] = {1, 1};
mint IF[100001] = {1, 1};
mint I[100001] = {0, 1};
mint dp[53][50001];
int N;
char S[100001];
int A[52];
int A_[52];
int min(int x, int y) { return x < y ? x : y; }
int f(int c) {
  if ('a' <= c && c <= 'z') {
    return c - 'a';
  } else {
    return c - 'A' + 26;
  }
}
void susume(int i) {
  if (A[i] == 0) {
    for (int j = 0; j <= N / 2; j++) {
      dp[i + 1][j] = dp[i][j];
    }
  } else {
    for (int j = 0; j <= N / 2; j++) {
      if (j >= A[i]) {
        dp[i + 1][j] = dp[i][j] + dp[i][j - A[i]];
      } else {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }
}
void modore(int i) {
  for (int j = 0; j <= N / 2; j++) {
    if (j >= A[i]) {
      dp[i][j] = dp[i + 1][j] - dp[i][j - A[i]];
    } else {
      dp[i][j] = dp[i + 1][j];
    }
  }
}
int main() {
  for (int i = 2; i <= 100000; i++) {
    I[i] = I[1000000007 % i] * (1000000007 - 1000000007 / i);
    F[i] = i * F[i - 1];
    IF[i] = I[i] * IF[i - 1];
  }
  scanf("%s", S);
  N = strlen(S);
  for (int i = 0; i < N; i++) {
    A[f(S[i])]++;
  }
  dp[0][0] = 1;
  for (int i = 0; i < 52; i++) {
    susume(i);
  }
  for (int i = 0; i < 52; i++) {
    A_[i] = A[i];
  }
  static mint ans[52][52];
  for (int x = 0; x < 52; x++) {
    if (A_[x] == 0) continue;
    ans[x][x] = dp[52][N / 2];
    A[51] = A_[x];
    modore(51);
    for (int y = x + 1; y < 52; y++) {
      if (A_[y] == 0) continue;
      A[50] = A_[y];
      modore(50);
      int s = A_[x] + A_[y];
      if (s > N / 2) {
        ans[x][y] = ans[y][x] = 0;
      } else {
        ans[x][y] = ans[y][x] = dp[50][N / 2] + dp[50][N / 2 - s];
      }
    }
  }
  mint v = F[N / 2] * F[N / 2];
  for (int i = 0; i < 52; i++) {
    v *= IF[A_[i]];
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    x = f(S[x]);
    y = f(S[y]);
    printf("%d\n", (v * ans[x][y]).n);
  }
  return 0;
}