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;
inline int rei() {
  int x;
  cin >> x;
  return x;
}
inline long long rel() {
  long long x;
  cin >> x;
  return x;
}
inline string res() {
  string x;
  cin >> x;
  return x;
}
struct Fact {
  vector<long long> f;
  vector<long long> rf;
  long long pow(long long N, long long K) {
    if (K == 0) {
      return 1;
    } else if (K % 2 == 0) {
      long long t = pow(N, K / 2);
      return t * t % 1000000007;
    } else {
      return N * pow(N, K - 1) % 1000000007;
    }
  }
  Fact(int N) : f(N + 1), rf(N + 1) {
    for (int i = 0; i < N + 1; i++) {
      if (i == 0) {
        f[i] = 1;
      } else {
        f[i] = (f[i - 1] * i) % 1000000007;
      }
    }
    for (int i = N; i >= 0; i--) {
      if (i == N) {
        rf[i] = pow(f[N], 1000000007 - 2);
      } else {
        rf[i] = rf[i + 1] * (i + 1) % 1000000007;
      }
    }
  }
  long long GetFact(int N) { return f[N]; }
  long long GetPerm(int N, int R) { return f[N] * rf[N - R] % 1000000007; }
  long long GetConv(int N, int R) {
    return ((f[N] * rf[R]) % 1000000007 * rf[N - R]) % 1000000007;
  }
  long long GetRev(int N) {
    if (N == 0) {
      return 1;
    } else {
      return rf[N] * f[N - 1] % 1000000007;
    }
  }
};
int C[52];
int chartoint(char c) {
  if ('a' <= c && c <= 'z') {
    return c - 'a';
  } else {
    return c - 'A' + 26;
  }
}
long long DP[100001];
int N;
void Plus(int X) {
  if (X == 0) {
    return;
  }
  for (int i = N / 2; i >= X; i--) {
    DP[i] += DP[i - X];
    if (DP[i] >= 1000000007) {
      DP[i] -= 1000000007;
    }
  }
}
void Minus(int X) {
  if (X == 0) {
    return;
  }
  for (int i = X; i <= N / 2; i++) {
    DP[i] -= DP[i - X];
    if (DP[i] < 0) {
      DP[i] += 1000000007;
    }
  }
}
long long ans[52][52];
void Calc() {
  string S = res();
  N = S.length();
  Fact F(N);
  for (int i = 0; i < N; i++) {
    C[chartoint(S[i])]++;
  }
  long long rev = 1;
  for (int i = 0; i < 52; i++) {
    rev *= F.rf[C[i]];
    rev %= 1000000007;
  }
  DP[0] = 1;
  for (int i = 0; i < 52; i++) {
    Plus(C[i]);
  }
  long long all = DP[N / 2] * F.GetFact(N / 2) % 1000000007 * F.GetFact(N / 2) %
                  1000000007 * rev % 1000000007;
  for (int i = 0; i < 52; i++) {
    ans[i][i] = all;
  }
  for (int i = 1; i < 52; i++) {
    Minus(C[i]);
    for (int j = 0; j < i; j++) {
      Minus(C[j]);
      long long c = DP[N / 2] * F.GetFact(N / 2) % 1000000007 *
                    F.GetFact(N / 2) % 1000000007 * 2 * rev % 1000000007;
      ans[i][j] = c;
      ans[j][i] = c;
      Plus(C[j]);
    }
    Plus(C[i]);
  }
  int Q = rei();
  for (int query = 0; query < Q; query++) {
    int x0 = rei() - 1;
    int y0 = rei() - 1;
    int x = chartoint(S[x0]);
    int y = chartoint(S[y0]);
    cout << ans[x][y] << endl;
  }
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  cout.tie(0);
  Calc();
  return 0;
}