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("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
inline void setmin(int &x, int y) {
  if (y < x) x = y;
}
inline void setmax(int &x, int y) {
  if (y > x) x = y;
}
inline void setmin(long long &x, long long y) {
  if (y < x) x = y;
}
inline void setmax(long long &x, long long y) {
  if (y > x) x = y;
}
const int N = 100000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
inline void add(int &x, int y) {
  x += y;
  if (x >= MOD) {
    x -= MOD;
  }
}
long long bin_pow(long long a, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) {
      res = res * a % MOD;
    }
    a = a * a % MOD;
    p >>= 1;
  }
  return res;
}
long long inv(long long x) { return bin_pow(x, MOD - 2); }
long long fact[N + 1], rfact[N + 1];
void init() {
  fact[0] = 1;
  for (int i = 1; i < N + 1; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  rfact[N] = inv(fact[N]);
  for (int i = N - 1; i > -1; i--) {
    rfact[i] = rfact[i + 1] * (i + 1) % MOD;
  }
}
char s[N + 1];
int mapa[256];
int dp[100][N / 2 + 1];
int dp1[100][N / 2 + 1];
int OUT[100][100];
int main() {
  init();
  scanf("%s", s);
  int n = strlen(s);
  for (int i = 0; i < n; i++) {
    mapa[s[i]]++;
  }
  long long val = fact[n / 2] * fact[n / 2] % MOD;
  vector<int> cnt;
  for (int i = 0; i < 256; i++) {
    if (mapa[i] > 0) {
      cnt.push_back(mapa[i]);
      val = val * inv(fact[mapa[i]]) % MOD;
    }
  }
  sort(cnt.begin(), cnt.end());
  for (int s = 0; s < (int)cnt.size(); s++) {
    const int N2 = n / 2;
    fill(dp[0], dp[0] + N2 + 1, 0);
    dp[0][0] = 1;
    for (int i = 0; i < (int)cnt.size() - 1; i++) {
      int CCC = cnt[(s + (i + 1)) % (int)cnt.size()];
      fill(dp[i + 1], dp[i + 1] + N2 + 1, 0);
      for (int c = 0; c < N2 + 1; c++) {
        add(dp[i + 1][c], dp[i][c]);
        if (c + CCC <= N2) {
          add(dp[i + 1][c + CCC], dp[i][c]);
        }
      }
    }
    fill(dp1[0], dp1[0] + N2 + 1, 0);
    dp1[0][0] = 1;
    for (int i = 0; i < (int)cnt.size() - 1; i++) {
      int CCC = cnt[(s - (i + 1) + (int)cnt.size()) % (int)cnt.size()];
      fill(dp1[i + 1], dp1[i + 1] + N2 + 1, 0);
      for (int c = 0; c < N2 + 1; c++) {
        add(dp1[i + 1][c], dp1[i][c]);
        if (c + CCC <= N2) {
          add(dp1[i + 1][c + CCC], dp1[i][c]);
        }
      }
    }
    OUT[s][s] = dp[(int)cnt.size() - 1][N2];
    for (int t = 0; t < (int)cnt.size(); t++) {
      if (t == s) {
        continue;
      }
      int p1 = (t - s + (int)cnt.size()) % (int)cnt.size();
      int p2 = (s - t + (int)cnt.size()) % (int)cnt.size();
      for (int c = 0; c < N2 + 1; c++) {
        OUT[s][t] =
            (OUT[s][t] + (long long)dp[p1 - 1][c] * dp1[p2 - 1][N2 - c]) % MOD;
      }
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    int p1 = lower_bound(cnt.begin(), cnt.end(), mapa[s[x]]) - cnt.begin();
    int p2 = lower_bound(cnt.begin(), cnt.end(), mapa[s[y]]) - cnt.begin();
    if (p1 == p2) {
      p2++;
    }
    if (s[x] == s[y]) {
      cout << OUT[p1][p1] * val * 2 % MOD << "\n";
    } else {
      cout << OUT[p1][p2] * val * 2 % MOD << "\n";
    }
  }
  return 0;
}