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;
namespace IO {
const int maxn(1 << 21 | 1);
char *iS, *iT, ibuf[maxn], obuf[maxn], *oS = obuf, *oT = obuf + maxn - 1, c,
                                       st[20];
int f, tp, len;
inline char getc() {
  return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin),
                     iS == iT ? EOF : *iS++)
                  : *iS++;
}
template <class T>
inline void read(T &x) {
  for (c = getc(), f = 1; c < '0' || c > '9'; c = getc()) f = c == '-' ? -1 : 1;
  for (x = 0; c >= '0' && c <= '9'; c = getc()) x = x * 10 + (c ^ 48);
  x *= f;
}
template <class T, class... Other>
inline void read(T &x, Other &...y) {
  read(x), read(y...);
}
inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; }
inline void putc(char ch) {
  *oS++ = ch;
  if (oS == oT) flush();
}
template <class T>
inline void print(T x, char ch = '\n') {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) st[++tp] = x % 10 + '0', x /= 10;
  while (tp) putc(st[tp--]);
  putc(ch);
}
template <class T, class... Other>
inline void print(T x, Other... y) {
  print(x), print(y...);
}
inline void print_str(char *s) {
  for (len = strlen(s), f = 0; f < len; ++f) putc(s[f]);
}
inline void read_str(char *s, int &l) {
  for (l = 0, c = getc(); (c < 'a' || c > 'z') && (c < 'A' || c > 'Z');
       c = getc())
    ;
  for (; (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); c = getc())
    s[l++] = c;
  s[l] = '\0';
}
}  // namespace IO
using IO ::flush;
using IO ::print;
using IO ::print_str;
using IO ::read;
using IO ::read_str;
template <class T>
inline void cmax(T &x, T y) {
  x = x >= y ? x : y;
}
template <class T, class... Other>
inline void cmax(T &x, T y, Other... z) {
  Cmax(x, y), Cmax(x, z...);
}
template <class T>
inline void cmin(T &x, T y) {
  x = x <= y ? x : y;
}
template <class T, class... Other>
inline void cmin(T &x, T y, Other... z) {
  Cmin(x, y), Cmin(x, z...);
}
inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
const int mod(1e9 + 7);
inline void inc(int &x, const int y) { x = x + y >= mod ? x + y - mod : x + y; }
inline void dec(int &x, const int y) { x = x - y < 0 ? x - y + mod : x - y; }
inline int add(const int x, const int y) {
  return x + y >= mod ? x + y - mod : x + y;
}
inline int sub(const int x, const int y) {
  return x - y < 0 ? x - y + mod : x - y;
}
inline int fpow(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1) ret = ret * x % mod;
  return ret;
}
const int maxn(1e5 + 5);
int n, q, fac[maxn], inv[maxn], f[maxn], cnt[256], ans[256][256], sum;
char s[maxn];
int main() {
  int i, j, mx = 1e5, x, y, tot;
  fac[0] = inv[0] = inv[1] = 1;
  for (i = 1; i <= mx; ++i) fac[i] = (long long)fac[i - 1] * i % mod;
  for (i = 2; i <= mx; ++i)
    inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod;
  for (i = 2; i <= mx; ++i) inv[i] = (long long)inv[i - 1] * inv[i] % mod;
  read_str(s, n), read(q), sum = 1;
  for (i = 0; i < n; ++i) ++cnt[s[i]];
  for (f[0] = 1, i = 0; i < 256; ++i)
    if (cnt[i]) {
      sum = (long long)sum * inv[cnt[i]] % mod;
      for (j = n - cnt[i]; ~j; --j) inc(f[j + cnt[i]], f[j]);
    }
  for (x = 0; x < 256; ++x)
    if (cnt[x] && cnt[x] <= (n >> 1)) {
      for (j = cnt[x]; j <= n; ++j) dec(f[j], f[j - cnt[x]]);
      for (y = 0; y < 256; ++y)
        if (cnt[y]) {
          if (x ^ y) {
            tot = cnt[x] + cnt[y];
            if (tot > (n >> 1)) continue;
            for (j = cnt[y]; j <= n; ++j) dec(f[j], f[j - cnt[y]]);
          } else
            tot = cnt[x];
          ans[x][y] = (long long)f[(n >> 1) - tot] * fac[n >> 1] % mod * sum %
                      mod * fac[n >> 1] % mod * 2 % mod;
          if (x ^ y) {
            for (j = n - cnt[y]; ~j; --j) inc(f[j + cnt[y]], f[j]);
          }
        }
      for (j = n - cnt[x]; ~j; --j) inc(f[j + cnt[x]], f[j]);
    }
  while (q--) read(x, y), print(ans[s[x - 1]][s[y - 1]]);
  return flush(), 0;
}