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>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ii = pair<int, int>;
using ll = long long;
using db = long double;
using PT = pair<ll, ll>;
const int N = 1e5 + 5, K = 305, MOD = 1e9 + 7;
const ll MX = 1e15;
ll first[N], iF[N];
int fast(int b, int e) {
  if (!e) return 1;
  if (e & 1) return 1ll * b * fast(b, e - 1) % MOD;
  return fast(1ll * b * b % MOD, e >> 1);
}
ll C(int n, int k) {
  if (k > n) return 0;
  return 1ll * first[n] * iF[k] % MOD * iF[n - k] % MOD;
}
ll totIF;
string s;
int n;
int ans[256][256];
int cnt[256];
int dp[N];
void init() {
  first[0] = iF[0] = 1;
  for (int i = 1; i < N; i++) {
    first[i] = 1ll * i * first[i - 1] % MOD;
    iF[i] = fast(first[i], MOD - 2);
  }
  totIF = 1;
  for (char c = 'A'; c <= 'z'; c++) totIF = totIF * iF[cnt[c]] % MOD;
}
void add(int c) {
  for (int j = n / 2; j >= c; --j) {
    dp[j] += dp[j - c];
    if (dp[j] >= MOD) dp[j] -= MOD;
  }
}
void rem(int c) {
  for (int j = c; j <= n / 2; ++j) {
    dp[j] -= dp[j - c];
    if (dp[j] < 0) dp[j] += MOD;
  }
}
int solve(char c1, char c2) {
  int tot = cnt[c1] + cnt[c2] - (c1 == c2) * cnt[c2];
  if (tot > n / 2) return 0;
  ll ret = dp[n / 2 - tot];
  ret = ret * first[n / 2] % MOD;
  ret = ret * first[n / 2] % MOD;
  ret = ret * totIF % MOD;
  ret += ret;
  if (ret >= MOD) ret -= MOD;
  return ret;
}
void initKnapSack() {
  dp[0] = 1;
  for (char c = 'A'; c <= 'z'; c++)
    if (cnt[c]) add(cnt[c]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  n = s.size();
  for (auto c : s) cnt[c]++;
  init();
  initKnapSack();
  for (char c = 'A'; c <= 'z'; c++)
    if (cnt[c]) {
      rem(cnt[c]);
      for (char c2 = c; c2 <= 'z'; c2++)
        if (cnt[c2]) {
          if (c != c2) rem(cnt[c2]);
          ans[c][c2] = solve(c, c2);
          if (c != c2) add(cnt[c2]);
        }
      add(cnt[c]);
    }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    if (s[x] > s[y]) swap(x, y);
    cout << ans[s[x]][s[y]] << '\n';
  }
  return 0;
}