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;
long long read() {
  int f = 1;
  long long res = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -f;
  } while (ch < '0' || ch > '9');
  do {
    res = res * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f == 1 ? res : -res;
}
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 100010;
const int mod = 1000000007;
const long long INF = 1e18;
int n, m, q;
int A[N], B[N];
char str[N];
int head[N * 2], to[N * 2], nxt[N * 2], tot;
void addEdge(int u, int v) {
  tot++;
  nxt[tot] = head[u];
  to[tot] = v;
  head[u] = tot;
}
template <class T>
T mmax(T a, T b) {
  return a < b ? b : a;
}
template <class T>
T mmin(T a, T b) {
  return a < b ? a : b;
}
int countOne(int set) {
  int res = 0;
  while (set) {
    res++;
    set &= set - 1;
  }
  return res;
}
bool contain(int set, int i) { return (set & (1 << i)) > 0; }
long long myPow(long long a, int p) {
  if (p == 0) return 1;
  long long res = myPow(a, p / 2);
  res *= res;
  res %= mod;
  if (p % 2 == 1) {
    res *= a;
    res %= mod;
  }
  return res;
}
void addMode(int &a, long long b) { a = (a + b) % mod; }
long long mul(long long a, long long b) { return a * b % mod; }
template <class T>
void mySwap(T &a, T &b) {
  T tmp = a;
  a = b;
  b = tmp;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long dp[N], ndp[N];
bool has[N];
long long p[N], inv[N];
long long dp2[52][52];
long long C(int a, int b) {
  if (a == 0) return 1;
  return p[a] * inv[b] % mod * inv[a - b] % mod;
}
int getIdx(char ch) {
  if (ch >= 'a' && ch <= 'z')
    return ch - 'a';
  else
    return ch - 'A' + 26;
}
void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += mod;
}
int main() {
  fast_io();
  cin >> str;
  n = strlen(str);
  p[0] = p[1] = 1;
  for (int i = 2; i <= n; i++) {
    p[i] = p[i - 1] * i % mod;
  }
  for (int i = 0; i <= n; i++) {
    inv[i] = myPow(p[i], mod - 2);
  }
  int cnt[52];
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < n; i++) {
    if (str[i] >= 'a' && str[i] <= 'z')
      cnt[str[i] - 'a']++;
    else
      cnt[str[i] - 'A' + 26]++;
  }
  vector<int> len;
  for (int i = 0; i < 52; i++)
    if (cnt[i]) len.push_back(cnt[i]);
  memset(dp, 0, sizeof(dp));
  memset(has, false, sizeof(has));
  dp[0] = 1;
  has[0] = true;
  for (int i = 0; i < len.size(); i++) {
    for (int j = n; j >= 0; j--)
      if (has[j]) {
        has[j + len[i]] = true;
        dp[j + len[i]] = (dp[j + len[i]] + dp[j]) % mod;
      }
  }
  long long total = p[n / 2] * p[n / 2] % mod;
  for (int i = 0; i < len.size(); i++) {
    total = total * inv[len[i]] % mod;
  }
  total = total * dp[n / 2] % mod;
  memset(dp2, 0, sizeof(dp2));
  for (int i = 0; i < 52; i++)
    for (int j = i + 1; j < 52; j++)
      if (cnt[i] && cnt[j] && cnt[i] + cnt[j] <= n / 2) {
        for (int k = 0; k <= n; k++) ndp[k] = dp[k];
        for (int k = cnt[i]; k <= n; k++) {
          sub(ndp[k], ndp[k - cnt[i]]);
        }
        for (int k = cnt[j]; k <= n; k++) {
          sub(ndp[k], ndp[k - cnt[j]]);
        }
        long long tmp = p[n / 2] * p[n / 2] % mod;
        for (int k = 0; k < 52; k++)
          if (cnt[k]) {
            tmp = tmp * inv[cnt[k]] % mod;
          }
        tmp = tmp * ndp[n / 2] * 2 % mod;
        dp2[i][j] = dp2[j][i] = tmp;
      }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (str[a] == str[b]) {
      cout << total << '\n';
    } else {
      int ia = getIdx(str[a]);
      int ib = getIdx(str[b]);
      cout << dp2[ia][ib] << '\n';
    }
  }
  return 0;
}