#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
char s[1000007];
char t[1000007];
int q[100000];
bool occur[67108865];
short id[67108865];
int sol[100000];
int main() {
  gets(s);
  int n, total = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%s", t);
    int len = strlen(t), mask = 0;
    for (int i = 0; i < len; i++) mask |= 1 << (int)(t[i] - 'a');
    q[i] = mask;
    id[mask] = i + 1;
  }
  int m = strlen(s);
  int S[555], T[555], cnt = 0;
  int *A = S, *B = T;
  for (int i = 0; i < m; i++) {
    int cur = 1 << (int)(s[i] - 'a'), cnt1 = 0;
    B[cnt1++] = cur;
    for (int j = 0; j < cnt; j++) {
      B[cnt1++] = cur | A[j];
      occur[A[j]] = true;
    }
    sort(B, B + cnt1);
    cnt1 = unique(B, B + cnt1) - B;
    for (int j = 0; j < cnt1; j++) {
      if (!occur[B[j]] && id[B[j]]) ++sol[id[B[j]] - 1];
    }
    for (int j = 0; j < cnt; j++) occur[A[j]] = false;
    swap(A, B);
    cnt = cnt1;
  }
  for (int i = 0; i < n; i++) {
    cout << sol[id[q[i]] - 1] << endl;
  }
  return 0;
}
