#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int nex[MAXN][26], f[10005], ans[10005];
char st[MAXN], s[27];
pair<int, char> px[26];
short int p[67108864];
int main() {
  int len, m;
  scanf("%s", st + 1);
  len = strlen(st + 1);
  for (int i = 0; i < 26; i++) nex[len + 1][i] = len + 1;
  for (int i = len; i; i--) {
    memcpy(nex[i], nex[i + 1], sizeof(nex[i]));
    nex[i][st[i] - 97] = i;
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%s", s + 1);
    for (int j = strlen(s + 1); j; j--) f[i] += 1 << s[j] - 97;
    p[f[i]] = i;
  }
  for (int i = 1; i <= len; i++) {
    if (i - 1 && st[i] == st[i - 1]) continue;
    int f = 0, top = 0;
    for (int j = 0; j < 26; j++)
      if (nex[i][j] != len + 1 &&
          (i == 1 || nex[i][j] < nex[i][st[i - 1] - 97]))
        px[top++] = make_pair(nex[i][j], j);
    sort(px, px + top);
    for (int j = 0; j < top; j++) {
      f += 1 << px[j].second;
      if (p[f]) ans[p[f]]++;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[p[f[i]]]);
  return 0;
}
