#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int n, m, h[maxn], code[maxn][26], ord[26], num[26];
char s[maxn], c[10010][27];
unordered_map<int, int> mp;
bool comp(int x, int y) { return num[x] < num[y]; }
int main() {
  scanf("%s %d", s + 1, &m), n = strlen(s + 1);
  for (int i = 1; i <= m; i++) {
    scanf("%s", c[i] + 1);
    int l = strlen(c[i] + 1);
    for (int j = 1; j <= l; j++) {
      h[i] |= (1 << (c[i][j] - 'a'));
    }
    mp[h[i]] = 0;
  }
  for (int i = 0; i < 26; i++) ord[i] = i;
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j < 26; j++) {
      if (s[i] == j + 'a')
        num[j] = i;
      else if (i == n)
        num[j] = n + 1;
    }
    sort(ord, ord + 26, comp);
    for (int j = 0, k = 0; j < 26; j++) {
      if (num[ord[j]] == n + 1) break;
      k |= (1 << ord[j]), code[i][j] = k;
      if ((i == n || code[i][j] != code[i + 1][j]) && mp.count(k)) mp[k]++;
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\n", mp[h[i]]);
  }
  return 0;
}
