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>
clock_t t = clock();
namespace my_std {
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline T rnd(T l, T r) {
  return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T& t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
char __sr[1 << 21], __z[20];
int __C = -1, __Z = 0;
inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }
inline void print(register int x) {
  if (__C > 1 << 20) Ot();
  if (x < 0) __sr[++__C] = '-', x = -x;
  while (__z[++__Z] = x % 10 + 48, x /= 10)
    ;
  while (__sr[++__C] = __z[__Z], --__Z)
    ;
  __sr[++__C] = '\n';
}
void file() {}
inline void chktime() {}
long long ksm(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x % 1000000007)
    if (y & 1) ret = ret * x % 1000000007;
  return ret;
}
long long inv(long long x) { return ksm(x, 1000000007 - 2); }
}  // namespace my_std
using namespace my_std;
int n, m, K;
char s[101101];
int a[101101], aa[101101];
int cnt[233];
long long T;
long long fac[101101], _fac[101101];
void init() {
  fac[0] = _fac[0] = 1;
  for (int i = (1); i <= (101101 - 1); i++)
    fac[i] = fac[i - 1] * i % 1000000007, _fac[i] = inv(fac[i]);
}
long long C(int n, int m) {
  return n >= m && m >= 0
             ? fac[n] * _fac[m] % 1000000007 * _fac[n - m] % 1000000007
             : 0;
}
int sum[66];
long long dp[101101], cur[101101];
long long ans[66][66];
void Init() {
  for (int i = (1); i <= (K); i++) sum[i] = sum[i - 1] + cnt[i];
  dp[0] = 1;
  int n = ::n >> 1;
  for (int i = (1); i <= (K); i++)
    for (int j = (n); j >= (cnt[i]); j--)
      dp[j] = (dp[j] + dp[j - cnt[i]]) % 1000000007;
}
long long solve(int x, int y) {
  int n = ::n >> 1;
  if ((cnt[x] > n && x == y) || (cnt[x] + cnt[y] > n && x != y)) return 0;
  long long c = fac[n] * fac[n] % 1000000007 * inv(T) % 1000000007;
  if (x == y) return c * dp[n] % 1000000007;
  for (int i = (0); i <= (n); i++) cur[i] = dp[i];
  for (int j = (cnt[x]); j <= (n); j++)
    cur[j] = (cur[j] - cur[j - cnt[x]] + 1000000007) % 1000000007;
  for (int j = (cnt[y]); j <= (n); j++)
    cur[j] = (cur[j] - cur[j - cnt[y]] + 1000000007) % 1000000007;
  return c * cur[n - cnt[x] - cnt[y]] * 2 % 1000000007;
}
int main() {
  file();
  cin >> (s + 1);
  n = strlen(s + 1);
  for (int i = (1); i <= (n); i++) a[i] = aa[i] = s[i];
  sort(aa + 1, aa + n + 1);
  K = unique(aa + 1, aa + n + 1) - aa - 1;
  for (int i = (1); i <= (n); i++)
    a[i] = lower_bound(aa + 1, aa + K + 1, a[i]) - aa;
  for (int i = (1); i <= (n); i++) ++cnt[a[i]];
  init();
  Init();
  T = 1;
  for (int i = (1); i <= (K); i++) T = T * fac[cnt[i]] % 1000000007;
  for (int i = (1); i <= (K); i++)
    for (int j = (1); j <= (K); j++) ans[i][j] = solve(i, j);
  read(m);
  int x, y;
  while (m--) read(x, y), printf("%lld\n", ans[a[x]][a[y]]);
  return 0;
}