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 fac[100001];
long long inv_fac[100001];
int val[100001];
vector<int> cnt(53, 0);
int l[100001];
int r[100001];
long long keep[53][53];
long long dp[54][100001];
long long dp1[54][100001];
long long mod = 1e9 + 7;
inline void add(long long &a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
}
inline void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += mod;
}
long long pw(long long x, int p) {
  if (p == 0) return 1;
  if (p == 1) return x % mod;
  long long temp = pw(x, p / 2);
  temp = (temp * temp) % mod;
  if (p % 2 == 0) return temp;
  temp = (x * temp) % mod;
  return temp;
}
void calc() {
  fac[0] = fac[1] = 1;
  inv_fac[0] = inv_fac[1] = 1;
  for (int i = 2; i <= 100000; i++) {
    fac[i] = (i * fac[i - 1]) % mod;
    inv_fac[i] = pw(fac[i], mod - 2);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) cin >> l[i] >> r[i];
  int n = s.size();
  int mx = n / 2;
  calc();
  for (int i = 0; i < n; i++) {
    if (s[i] >= 'a' && s[i] <= 'z') {
      val[i + 1] = int(s[i] - 'a') + 1;
      cnt[int(s[i] - 'a') + 1]++;
    } else {
      val[i + 1] = 26 + int(s[i] - 'A') + 1;
      cnt[26 + int(s[i] - 'A') + 1]++;
    }
  }
  for (int i = 1; i <= 52; i++) {
    int temp = cnt[i];
    if (temp > n / 2 || cnt[i] == 0) {
      continue;
    }
    temp = n / 2 - temp;
    for (int w = 0; w <= mx; w++) dp[0][w] = dp1[53][w] = 0;
    dp[0][0] = dp1[53][0] = 1;
    for (int k = 1; k <= 52; k++) {
      if (k == i || cnt[k] == 0) {
        for (int w = 0; w <= mx; w++) dp[k][w] = dp[k - 1][w];
        continue;
      }
      for (int w = 0; w <= mx; w++) {
        dp[k][w] = dp[k - 1][w];
        if (w >= cnt[k]) add(dp[k][w], dp[k - 1][w - cnt[k]]);
      }
    }
    for (int k = 52; k >= 1; k--) {
      if (k == i || cnt[k] == 0) {
        for (int w = 0; w <= mx; w++) dp1[k][w] = dp1[k + 1][w];
        continue;
      }
      for (int w = 0; w <= mx; w++) {
        dp1[k][w] = dp1[k + 1][w];
        if (w >= cnt[k]) add(dp1[k][w], dp1[k + 1][w - cnt[k]]);
      }
    }
    for (int k = i; k <= 52; k++) {
      if (k == i) {
        keep[k][i] = dp[52][temp];
        continue;
      }
      long long t1 = 0;
      int rem = temp - cnt[k];
      if (rem < 0) {
        keep[k][i] = keep[i][k] = 0;
        continue;
      }
      for (int w = 0; w <= rem; w++) {
        long long t2 = (dp[k - 1][w] * dp1[k + 1][rem - w]) % mod;
        add(t1, t2);
      }
      keep[i][k] = keep[k][i] = t1;
    }
  }
  long long ans = (fac[n / 2] * fac[n / 2]) % mod;
  for (int i = 1; i <= 52; i++) ans = (ans * inv_fac[cnt[i]]) % mod;
  ans = (2 * ans) % mod;
  for (int i = 0; i < q; i++) {
    int x = val[l[i]];
    int y = val[r[i]];
    long long temp = ans;
    temp = (temp * keep[x][y]) % mod;
    cout << temp << endl;
  }
}