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;
void open(const char *s) {}
void open2(const char *s) {}
template <class T>
int upmin(T &a, const T &b) {
  return (b < a ? a = b, 1 : 0);
}
template <class T>
int upmax(T &a, const T &b) {
  return (b > a ? a = b, 1 : 0);
}
namespace io {
const int SIZE = (1 << 20) + 1;
char ibuf[SIZE], *iS, *iT;
char obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1;
int getc() {
  (iS == iT ? iS = ibuf, iT = ibuf + fread(ibuf, 1, SIZE, stdin) : 0);
  return iS == iT ? EOF : *(iS++);
}
int f;
char c;
template <class T>
void get(T &x) {
  f = 1;
  for (c = getc(); (c < '0' || c > '9') && c != '-'; c = getc())
    ;
  (c == '-' ? f = -1, c = getc() : 0);
  x = 0;
  for (; c >= '0' && c <= '9'; c = getc()) x = x * 10 + c - '0';
  x *= f;
}
void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
void putc(char x) {
  *(oS++) = x;
  if (oS == oT) flush();
}
int a[55], t;
template <class T>
void put(T x) {
  if (!x) putc('0');
  x < 0 ? putc('-'), x = -x : 0;
  while (x) {
    a[++t] = x % 10;
    x /= 10;
  }
  while (t) putc(a[t--] + '0');
}
void space() { putc(' '); }
void enter() { putc('\n'); }
struct flusher {
  ~flusher() { flush(); }
} io_flusher;
}  // namespace io
const int p = 1000000007;
const int N = 100010;
char str[N];
int f[60][50010], g[50010], h[50010];
int b1[60][100010], b2[60][100010];
int n, a[60], s[60];
int ans[60][60];
int fac[N], ifac[N], inv[N];
int binom(int x, int y) {
  return (long long)fac[x] * ifac[y] % p * ifac[x - y] % p;
}
int invbinom(long long x, long long y) {
  return (long long)ifac[x] * fac[y] % p * fac[x - y] % p;
}
int get(char ch) {
  if (ch >= 'a' && ch <= 'z')
    return ch - 'a' + 1;
  else
    return ch - 'A' + 1 + 26;
}
void add(int &a, long long b) { a = (a + b) % p; }
int main() {
  open2("d");
  scanf("%s", str + 1);
  n = strlen(str + 1);
  for (int i = 1; i <= n; i++) a[get(str[i])]++;
  inv[1] = fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
  for (int i = 2; i <= n; i++) {
    inv[i] = (long long)-p / i * inv[p % i] % p;
    fac[i] = (long long)fac[i - 1] * i % p;
    ifac[i] = (long long)ifac[i - 1] * inv[i] % p;
  }
  f[0][0] = 1;
  for (int i = 1; i <= 52; i++) {
    s[i] = s[i - 1] + a[i];
    for (int j = 0; j <= n / 2; j++) {
      add(f[i][j], (long long)f[i - 1][j] * binom(s[i] - j, a[i]));
      if (a[i] && j + a[i] <= n / 2)
        add(f[i][j + a[i]], (long long)f[i - 1][j] * binom(j + a[i], a[i]));
    }
  }
  for (int i = 1; i <= 60; i++)
    for (int j = 0; j <= n; j++) {
      b1[i][j] = binom(j, a[i]);
      b2[i][j] = invbinom(j, a[i]);
    }
  for (int i = 1; i <= 52; i++) {
    memcpy(h, f[52], sizeof h);
    if (a[i])
      for (int k = 0; k <= n / 2; k++) {
        h[k] = (long long)h[k] * b2[i][s[52] - k] % p;
        if (k + a[i] <= n / 2)
          add(h[k + a[i]], (long long)-h[k] * b1[i][k + a[i]]);
      }
    for (int j = i; j <= 52; j++) {
      if (i == j) {
        ans[i][j] = (f[52][n / 2] % p + p) % p;
        continue;
      }
      memcpy(g, h, sizeof h);
      if (a[j])
        for (int k = 0; k <= n / 2; k++) {
          g[k] = (long long)g[k] * b2[j][s[52] - a[i] - k] % p;
          if (k + a[j] <= n / 2)
            add(g[k + a[j]], (long long)-g[k] * b1[j][k + a[j]]);
        }
      if (a[i] || a[j]) {
        g[n / 2] = (long long)g[n / 2] * binom(s[52] - n / 2, a[i] + a[j]) % p *
                   binom(a[i] + a[j], a[i]) % p;
        if (a[i] + a[j] <= n / 2)
          add(g[n / 2], (long long)g[n / 2 - a[i] - a[j]] *
                            binom(n / 2, a[i] + a[j]) % p *
                            binom(a[i] + a[j], a[i]));
      }
      ans[i][j] = (g[n / 2] % p + p) % p;
    }
  }
  int q, x, y;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &x, &y);
    x = get(str[x]);
    y = get(str[y]);
    if (x > y) swap(x, y);
    io::put(ans[x][y]);
    io::enter();
  }
  return 0;
}