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 int64_t MOD = 1e9 + 7;
void add(int64_t& a, int64_t b) { a = (a + b) % MOD; }
void mul(int64_t& a, int64_t b) { a = a * b % MOD; }
vector<int64_t> fact, seq_inv, fact_inv;
void create_fact_mod(int num) {
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i <= num; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
}
void create_seq_inv_mod(int num) {
  seq_inv[0] = 1;
  seq_inv[1] = 1;
  for (int i = 2; i <= num; i++) {
    seq_inv[i] = (MOD - MOD / i) * seq_inv[MOD % i] % MOD;
  }
}
void create_fact_inv_mod(int num) {
  fact_inv[0] = 1;
  fact_inv[1] = 1;
  for (int i = 2; i <= num; i++) {
    fact_inv[i] = fact_inv[i - 1] * seq_inv[i] % MOD;
  }
}
void create_mod_tables(int num) {
  fact.resize(num + 1);
  seq_inv.resize(num + 1);
  fact_inv.resize(num + 1);
  create_fact_mod(num);
  create_seq_inv_mod(num);
  create_fact_inv_mod(num);
}
int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {
  int64_t d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
int64_t inv_mod(int64_t a) {
  int64_t x, y;
  extgcd(a, MOD, x, y);
  return (MOD + x % MOD) % MOD;
}
int main() {
  string S;
  cin >> S;
  int N = S.size();
  create_mod_tables(N);
  map<char, int> mp;
  for (char c : S) mp[c]++;
  int K = mp.size();
  map<char, int> c2i;
  vector<int> nums;
  int64_t C = fact[N / 2] * fact[N / 2] % MOD;
  for (auto& p : mp) {
    c2i[p.first] = nums.size();
    nums.push_back(p.second);
    mul(C, fact_inv[p.second]);
  }
  static int64_t dp[100001];
  dp[0] = C;
  int sum = 0;
  for (int i = 0; i < K; i++) {
    for (int j = sum; j >= 0; j--) add(dp[j + nums[i]], dp[j]);
    sum += nums[i];
  }
  int64_t ans[52][52], dp2[100001];
  for (int a = 0; a < K; a++) {
    ans[a][a] = dp[N / 2];
    for (int b = 0; b < a; b++) {
      if (nums[a] + nums[b] > N / 2) {
        ans[a][b] = ans[b][a] = 0;
      } else {
        for (int j = 0; j <= N / 2; j++) dp2[j] = dp[j];
        for (int n : {nums[a], nums[b]}) {
          for (int j = n; j <= N / 2; j++) add(dp2[j], MOD - dp2[j - n]);
        }
        ans[a][b] = ans[b][a] =
            (dp2[N / 2] + dp2[N / 2 - nums[a] - nums[b]]) % MOD;
      }
    }
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int x, y;
    scanf("%d %d", &x, &y);
    int a = c2i[S[x - 1]], b = c2i[S[y - 1]];
    printf("%lld\n", ans[a][b]);
  }
  return 0;
}