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>
static const int mod = 1000000000 + 7;
char st[100000 + 1];
int q, su[26 + 26];
inline int evk3(int a, int b) {
  int av = a, bv = b;
  int p = 1, q = 0, r = 0, s = 1;
  int x, y;
  while (a != b)
    if (a < b) {
      int o = b / a;
      b = b - a * o;
      r = r - p * o;
      s = s - q * o;
      if (b == 0) {
        b = a;
        x = p;
        y = q;
      }
    } else {
      int o = a / b;
      a = a - b * o;
      p = p - r * o;
      q = q - s * o;
      if (a == 0) {
        a = b;
        x = r;
        y = s;
      }
    }
  return x;
}
inline int dd(char c) { return c >= 'a' && c <= 'z' ? c - 'a' : c - 'A' + 26; }
inline int mul(int amod, int bmod) {
  return (int)((long long)amod * bmod % mod);
}
inline int add(int amod, int bmod) {
  return amod > mod - bmod ? amod - (mod - bmod) : amod + bmod;
}
inline int xdiv(int amod, int b) {
  int x = evk3(b, mod);
  if (x < 0) x += mod;
  return (int)((long long)amod * x % mod);
}
int fulls[100000 + 1], halfs[100000 / 2 + 1];
inline int fa(int n) { return fulls[n]; }
inline int frag(int n, int a, int b) {
  return mul(mul(fulls[n - a - b], halfs[a]), halfs[b]);
}
int lens[100000 + 1], opts[100000 / 2], df[26 + 26];
bool dsg[26 + 26][26 + 26], ssg;
int dsv[26 + 26][26 + 26], ssv;
int main() {
  scanf("%s%d", st, &q);
  int len = (int)strlen(st);
  fulls[0] = fulls[1] = 1;
  for (int i = 2; i <= len; ++i) fulls[i] = mul(fulls[i - 1], i);
  halfs[0] = 1;
  for (int i = 1; i <= len / 2; ++i)
    halfs[i] = mul(halfs[i - 1], len / 2 - (i - 1));
  int dval = 1, susum = 0;
  for (int i = 0; i < len; ++i) ++su[dd(st[i])];
  for (int i = 0; i < sizeof(su) / sizeof(int); ++i) {
    df[i] = i;
    lens[su[i]] = i;
  }
  std::sort(df, df + sizeof(su) / sizeof(int),
            [](int a, int b) -> bool { return su[a] > su[b]; });
  int subs = 0;
  for (int i = 0; i < sizeof(su) / sizeof(int); ++i)
    if (su[df[i]] > 1) {
      dval = mul(dval, fa(su[df[i]]));
      susum += su[df[i]];
      ++subs;
    }
  for (int i = 0; i < q; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = dd(st[x - 1]);
    y = dd(st[y - 1]);
    if (su[x] < su[y]) std::swap(x, y);
    if (x == y)
      if (ssg) {
        printf("%d\n", ssv);
        continue;
      } else
        ssg = true;
    else if (dsg[lens[su[x]]][lens[su[y]]]) {
      printf("%d\n", dsv[lens[su[x]]][lens[su[y]]]);
      continue;
    } else
      dsg[lens[su[x]]][lens[su[y]]] = true;
    int sux = su[x], suy = su[y], sud, hardsum;
    su[x] = su[y] = 0;
    if (x == y) {
      sud = sux;
      hardsum = sux == 1 ? susum + 2 : susum;
    } else {
      sud = sux + suy;
      hardsum = susum;
      if (sux == 1) ++hardsum;
      if (suy == 1) ++hardsum;
    }
    int all = 0, cargo = std::min(hardsum, len / 2);
    opts[0] = 1;
    for (int s = 1; s <= cargo; ++s) opts[s] = 0;
    int softsum = 0;
    for (int r = 0; r < subs; ++r)
      if (su[df[r]] > 1) {
        for (int s = cargo;
             s >= std::max(su[df[r]], softsum - len / 2 + su[df[r]]); --s)
          opts[s] = add(opts[s], opts[s - su[df[r]]]);
        softsum += su[df[r]];
      }
    for (int s = cargo; s >= std::max(sud, softsum - len / 2 + sud); --s)
      opts[s] = add(opts[s], opts[s - sud]);
    for (int s = std::max(0, hardsum - len / 2); s <= cargo; ++s)
      if (opts[s] > 0) all = add(all, mul(frag(len, s, hardsum - s), opts[s]));
    su[x] = sux;
    su[y] = suy;
    try {
      all = xdiv(all, dval);
    } catch (...) {
      throw;
    }
    (x == y ? ssv : dsv[lens[su[x]]][lens[su[y]]]) = all;
    printf("%d\n", all);
  }
}