#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void smn(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
inline void smx(T &a, const T &b) {
  if (b > a) a = b;
}
template <class T>
inline T rev(const T &a) {
  T _ = a;
  reverse(_.begin(), _.end());
  return _;
}
const double eps = 1e-9;
const long double leps = 1e-14;
map<int, int> cnt;
string s;
int sch[100000], m;
int last[100];
bitset<(1 << 26)> av;
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin >> s;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int now = 0;
    string tmp;
    cin >> tmp;
    for (int j = 0; j < tmp.size(); j++) now |= (1 << (tmp[j] - 'a'));
    sch[i] = now;
    av[now] = 1;
  }
  memset(last, -1, sizeof(last));
  for (int i = 0; i < s.size(); i++) {
    last[s[i] - 'a'] = i;
    vector<pair<int, int> > srt;
    for (int j = 0; j < 26; j++)
      if (last[j] != -1) srt.push_back(pair<int, int>(last[j], j));
    sort(srt.begin(), srt.end());
    int now = 0;
    for (int j = srt.size() - 1; j >= 0; j--) {
      now |= (1 << srt[j].second);
      if (av[now] &&
          (i + 1 == s.size() || (now | (1 << (s[i + 1] - 'a'))) != now))
        cnt[now]++;
    }
  }
  for (int i = 0; i < m; i++) cout << cnt[sch[i]] << '\n';
  return 0;
}
