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 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;
}
struct divshopa {
  divshopa() {}
};
struct bezshopa {
  bezshopa() {}
};
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) {
      r = r - p * (b / a);
      s = s - q * (b / a);
      b = b % a;
      if (b == 0) {
        b = a;
        x = (int)p;
        y = (int)q;
      }
    } else {
      p = p - r * (a / b);
      q = q - s * (a / b);
      a = a % b;
      if (a == 0) {
        a = b;
        x = (int)r;
        y = (int)s;
      }
    }
  if ((long long)x * av + (long long)y * bv != 1) throw bezshopa();
  return x;
}
inline int xdiv(int amod, int b) {
  int x = evk3(b, mod);
  if (x < 0) x += mod;
  if (x < 0 || x >= mod) throw divshopa();
  return (int)((long long)amod * x % mod);
}
inline int xdiv(int amod, int b, int mod) {
  int x = evk3(b, mod);
  if (x < 0) x += mod;
  if (x < 0 || x >= mod) throw divshopa();
  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(mul(fulls[n - a - b], halfs[a]), halfs[b]), 2);
}
std::pair<int, int> qs[100000];
int qr[100000], qf[100000], qx[100000], qy[100000];
int vars[26 + 26 + 1][100000 / 2];
int df[26 + 26], lens[100000 + 1];
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, hard = 0;
  for (int i = 0; i < len; ++i) ++su[dd(st[i])];
  for (int i = 0; i < sizeof(su) / sizeof(int); ++i) {
    lens[su[i]] = i;
    if (su[i] > 1) {
      dval = mul(dval, fa(su[i]));
      ++hard;
    }
  }
  for (int i = 0; i < sizeof(su) / sizeof(int); ++i) df[i] = i;
  std::sort(df, df + sizeof(su) / sizeof(int),
            [](int a, int b) -> bool { return su[a] > su[b]; });
  for (int i = 0; i < q; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    qf[i] = i;
    qs[i].first = dd(st[x - 1]);
    qs[i].second = dd(st[y - 1]);
    qx[i] = x;
    qy[i] = y;
    if (su[qs[i].first] < su[qs[i].second]) {
      int sw = qs[i].second;
      qs[i].second = qs[i].first;
      qs[i].first = sw;
    }
    (qs[i].first == qs[i].second
         ? ssg
         : dsg[lens[su[qs[i].first]]][lens[su[qs[i].second]]]) = true;
  }
  std::sort(qf, qf + q, [](int a, int b) -> bool {
    int lena = qs[a].first == qs[a].second ? su[qs[a].first]
                                           : su[qs[a].first] + su[qs[a].second];
    int lenb = qs[b].first == qs[b].second ? su[qs[b].first]
                                           : su[qs[b].first] + su[qs[b].second];
    return lena > lenb;
  });
  for (int i = 0; i < q; ++i) {
    int x, y, all = 0;
    x = qs[qf[i]].first;
    y = qs[qf[i]].second;
    bool varinces = false;
    if (x == y) {
      if (!ssg) {
        qr[qf[i]] = ssv;
        continue;
      }
    } else if (!dsg[lens[su[x]]][lens[su[y]]]) {
      qr[qf[i]] = dsv[lens[su[x]]][lens[su[y]]];
      continue;
    }
    if (x == y && su[x] <= len / 2) {
      int cargo = su[x], last = cargo;
      vars[0][su[x] - 1] = 1;
      for (int r = 0; r < hard; ++r)
        if (df[r] != x && df[r] != y) {
          cargo += su[df[r]];
          for (int s = last; s < std::min(cargo, len / 2); ++s) vars[r][s] = 0;
          last = cargo;
          vars[r + 1][su[x] - 1] = cargo - su[x] <= len / 2 ? 1 : 0;
          for (int s = su[x]; s + 1 < cargo - len / 2; ++s) vars[r + 1][s] = 0;
          for (int s = std::max(su[x], cargo - 1 - len / 2);
               s < std::min(cargo, len / 2); ++s)
            vars[r + 1][s] =
                add(vars[r][s],
                    (s + 1) - su[df[r]] >= su[x] ? vars[r][s - su[df[r]]] : 0);
        } else
          for (int s = su[x] - 1; s < std::min(cargo, len / 2); ++s)
            vars[r + 1][s] = vars[r][s];
      for (int s = su[x] - 1; s < std::min(cargo, len / 2); ++s)
        if (vars[hard][s] > 0)
          all = add(all, mul(frag(len, s + 1, cargo - s - 1), vars[hard][s]));
      varinces = true;
    } else if (x != y && su[x] + su[y] <= len / 2) {
      int cargo = su[x] + su[y], last = cargo;
      vars[0][su[x] + su[y] - 1] = 1;
      for (int r = 0; r < hard; ++r)
        if (df[r] != x && df[r] != y) {
          cargo += su[df[r]];
          for (int s = last; s < std::min(cargo, len / 2); ++s) vars[r][s] = 0;
          last = cargo;
          vars[r + 1][su[x] + su[y] - 1] =
              cargo - su[x] - su[y] <= len / 2 ? 1 : 0;
          for (int s = su[x] + su[y]; s + 1 < cargo - len / 2; ++s)
            vars[r + 1][s] = 0;
          for (int s = std::max(su[x] + su[y], cargo - 1 - len / 2);
               s < std::min(cargo, len / 2); ++s)
            vars[r + 1][s] =
                add(vars[r][s], (s + 1) - su[df[r]] >= su[x] + su[y]
                                    ? vars[r][s - su[df[r]]]
                                    : 0);
        } else
          for (int s = su[x] + su[y] - 1; s < std::min(cargo, len / 2); ++s)
            vars[r + 1][s] = vars[r][s];
      for (int s = su[x] + su[y] - 1; s < std::min(cargo, len / 2); ++s)
        if (vars[hard][s] > 0)
          all = add(all, mul(frag(len, s + 1, cargo - s - 1), vars[hard][s]));
      varinces = true;
    }
    if (varinces) try {
        (x == y ? ssv : dsv[lens[su[x]]][lens[su[y]]]) = qr[qf[i]] =
            xdiv(all, dval);
      } catch (const bezshopa&) {
        return 1;
      } catch (const divshopa&) {
        return 2;
      }
    else
      (x == y ? ssv : dsv[lens[su[x]]][lens[su[y]]]) = qr[qf[i]] = 0;
    (x == y ? ssg : dsg[lens[su[x]]][lens[su[y]]]) = false;
  }
  for (int i = 0; i < q; ++i) printf("%d\n", qr[i]);
  return 0;
}