#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);
  }
}
