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;
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int c2i(char c) {
  if (c >= 'a' && c <= 'z') return c - 'a';
  return c - 'A' + 26;
}
const long long mod = 1e9 + 7;
const int N = 100010;
long long fact[N], invf[N];
long long add(long long x, long long y) { return (x + y) % mod; }
long long mul(long long x, long long y) { return (x % mod) * (y % mod) % mod; }
long long powll(long long x, long long y) {
  long long res = 1LL;
  while (y) {
    if (y & 1LL) res *= x;
    res %= mod;
    x = (x * x) % mod;
    y >>= 1LL;
  }
  return res;
}
long long divll(long long x, long long y) {
  return (x * powll(y, mod - 2)) % mod;
}
long long nPr(long long n, long long r) {
  if (n < r || r < 0) return 0;
  return mul(fact[n], invf[n - r]);
}
long long nCr(long long n, long long r) {
  if (n < r || r < 0) return 0;
  return mul(mul(fact[n], invf[r]), invf[n - r]);
}
int main() {
  string s;
  cin >> s;
  fact[0] = invf[0] = 1;
  for (int i = 1; i <= N - 1; ++i) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  invf[N - 1] = divll(1, fact[N - 1]);
  for (int i = N - 1; i >= 1; --i) {
    invf[i - 1] = (invf[i] * i) % mod;
  }
  int n = s.length();
  vector<int> a(n);
  for (int i = 0; i < n; ++i) a[i] = c2i(s[i]);
  int m = 52;
  vector<int> cnt(m);
  for (int i = 0; i < n; ++i) cnt[a[i]]++;
  long long num = (fact[n / 2] * fact[n / 2]) % mod;
  for (int i = 0; i < m; ++i) num = (num * invf[cnt[i]]) % mod;
  vector<vector<int> > ans(m, vector<int>(m));
  vector<long long> dp(n + 1);
  dp[0] = 1;
  for (int i = 0; i < m; ++i) {
    if (!cnt[i]) continue;
    for (int j = n - cnt[i]; j >= 0; --j) {
      (dp[j + cnt[i]] += dp[j]) %= mod;
    }
  }
  for (int i = 0; i < m; ++i) ans[i][i] = dp[n / 2];
  for (int i = 0; i < m; ++i) {
    if (!cnt[i]) continue;
    vector<long long> dp2(dp);
    for (int j = cnt[i]; j <= n; ++j) {
      (dp2[j] += mod - dp2[j - cnt[i]]) %= mod;
    }
    for (int j = i + 1; j <= m - 1; ++j) {
      if (!cnt[j]) continue;
      for (int k = cnt[j]; k <= n; ++k) {
        (dp2[k] += mod - dp2[k - cnt[j]]) %= mod;
      }
      long long tmp = (2 * dp2[n / 2]) % mod;
      ans[i][j] = ans[j][i] = tmp;
      for (int k = n; k >= cnt[j]; --k) {
        (dp2[k] += dp2[k - cnt[j]]) %= mod;
      }
    }
  }
  int q = in();
  while (q--) {
    int l = in() - 1, r = in() - 1;
    l = a[l];
    r = a[r];
    cout << (num * ans[l][r]) % mod << endl;
  }
  return 0;
}