#include <string>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int mod = int(1e9) + 7;

long long binpow(long long a, long long b) {
  long long ret = 1;
  while (b > 0) {
    if (b % 2) {
      ret = (ret * a) % mod;
    }
    b /= 2;
    a = (a * a) % mod;
  }
  return ret;
}

long long inverse(long long a) {
  return binpow(a, mod - 2);
}

int main(void) {
  string s;
  cin >> s;
  
  int n = int(s.size());
  
  vector<vector<int>> fr(26);
  for (int j = 0; j < 26; j++) {
    vector<int> f(n);
    if (s[0] == j+'a') {
      f[0] = 1;
    }
    for (int i = 1; i < n; i++) {
      f[i] = f[i-1];
      if (s[i] == j+'a') {
        f[i]++;
      }
    }
    fr[j] = f;
  }
  
  vector<long long> fact(n+1);
  
  fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  
  int T;
  cin >> T;
  
  auto get_sum = [](vector<int>& ps, int l, int r) {
    return (l > 0) ? ps[r] - ps[l-1] : ps[r];
  };
  
  while (T--) {
    int l, r;
    cin >> l >> r;
    
    l--, r--;
      
    int m = 0, p = 0;
    vector<int> count(26);
    for (int i = 0; i < 26; i++) {
      count[i] = get_sum(fr[i], l, r);
      m += count[i] / 2;
      if (count[i] % 2) {
        p++;
      }
    }
    
    long long tot = fact[m];
    for (int i = 0; i < 26; i++) {
      tot = (tot * inverse(fact[count[i] / 2])) % mod;
    }
    
    if (p > 0) {
      tot = (tot * p) % mod;
    }
    
    printf("%lld\n", tot);
  }
  
  return 0;
}