#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
const int mod = 32771;
struct HashMap {
  int last[mod + 1];
  int nx[mod + 1], key[mod + 1], val[mod + 1], hc;
  inline void reset() {
    hc = 0;
    memset(last, -1, sizeof(last));
  }
  inline void cr(int k) {
    int h = k % mod;
    for (int w = last[h]; w >= 0; w = nx[w]) {
      if (key[w] == k) return;
    }
    key[hc] = k;
    val[hc] = 0;
    nx[hc] = last[h];
    last[h] = hc++;
  }
  inline void add(int v, int vv) {
    for (int w = last[v % mod]; w >= 0; w = nx[w]) {
      if (key[w] == v) {
        val[w] += vv;
        return;
      }
    }
  }
  inline int fnd(int v) {
    for (int w = last[v % mod]; w >= 0; w = nx[w]) {
      if (key[w] == v) return val[w];
    }
    return 0;
  }
};
int a, b, c, d, i, j, n, m, k;
int quer[10002];
char str[1000002], tmp[33];
int nx[26], ind[26];
struct cmp {
  bool operator()(const int &a, const int &b) const { return nx[a] < nx[b]; }
};
HashMap q;
int main() {
  q.reset();
  scanf("%s", str);
  n = (int)strlen(str);
  scanf("%d", &m);
  for (int _n((m)-1), i(0); i <= _n; i++) {
    scanf("%s", tmp);
    b = (int)strlen(tmp);
    int cmask = 0;
    for (int _n((b)-1), j(0); j <= _n; j++) cmask |= 1 << (tmp[j] - 'a');
    q.cr(cmask);
    quer[i] = cmask;
  }
  memset(nx, 63, sizeof(nx));
  for (int i = (n - 1), _b = (0); i >= _b; i--) {
    nx[str[i] - 'a'] = i;
    int mask = 0;
    for (int _n((26) - 1), j(0); j <= _n; j++) ind[j] = j;
    sort(ind, ind + 26, cmp());
    int pp = -1;
    if (i) pp = str[i - 1] - 'a';
    for (int _n((26) - 1), j(0); j <= _n; j++) {
      int v = ind[j];
      if (nx[v] >= 1000000000) break;
      mask |= 1 << v;
      if (i && (mask & 1 << pp)) break;
      q.add(mask, 1);
    }
  }
  for (int _n((m)-1), i(0); i <= _n; i++) {
    printf("%d\n", q.fnd(quer[i]));
  }
}
