#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) {
      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;
      }
    }
  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);
}
inline int xdiv(int amod, int b, int mod) {
  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(mul(fulls[n - a - b], halfs[a]), halfs[b]), 2);
}
std::pair<int, int> qs[100000];
int qr[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);
    qs[i].first = dd(st[x - 1]);
    qs[i].second = dd(st[y - 1]);
    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;
  }
  for (int i = 0; i < q; ++i) {
    int x, y, all = 0;
    x = qs[i].first;
    y = qs[i].second;
    bool varinces = false;
    if (x == y) {
      if (!ssg) {
        qr[i] = ssv;
        continue;
      }
    } else if (!dsg[lens[su[x]]][lens[su[y]]]) {
      qr[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[i] =
            xdiv(all, dval);
      } catch (...) {
        throw;
      }
    else
      (x == y ? ssv : dsv[lens[su[x]]][lens[su[y]]]) = qr[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;
}
