#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void input(T &x) {
  register char c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline long long bigmod(long long p, long long e, long long M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
const int N = 1e6 + 6;
char str[N], inp[26];
int qu[10001];
int main() {
  scanf("%s", str);
  int n = strlen(str);
  int q;
  input(q);
  int mask = 0;
  unordered_map<int, int> Map;
  for (int t = 0; t < q; t++) {
    scanf("%s ", inp);
    mask = 0;
    for (int i = 0; inp[i]; i++) {
      mask |= 1 << inp[i] - 'a';
    }
    qu[t] = mask;
    Map[mask] = 0;
  }
  for (int i = 0; i < n; i++) {
    mask = 0;
    for (int j = i; j < n; j++) {
      if (i < j && str[i] == str[j]) break;
      mask |= 1 << str[j] - 'a';
      if (j + 1 == n || (mask & 1 << str[j + 1] - 'a') == 0)
        if (Map.count(mask)) Map[mask]++;
    }
  }
  for (int i = 0; i < q; i++) {
    printf("%d\n", Map[qu[i]]);
  }
  return 0;
}
