#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f, g, h, i, j, k;
char w[1000006], ww[1000005];
int an[300005];
int G[300005];
set<pair<int, int> > GG;
set<pair<int, int> >::iterator in;
pair<int, int> H;
map<int, int> HH;
bitset<70000005> GGG;
int main() {
  scanf("%s", w + 1);
  d = strlen(w + 1);
  scanf("%d", &a);
  for (i = 1; i <= a; i++) {
    scanf("%s", ww + 1);
    c = strlen(ww + 1);
    k = 0;
    for (j = 1; j <= c; j++) k |= 1 << (ww[j] - 'a');
    G[i] = k;
    GGG[k] = 1;
  }
  for (i = 1; i <= d; i++) {
    k = 0;
    for (j = i; j <= d; j++) {
      if (w[j] == w[i - 1]) break;
      k |= 1 << (w[j] - 'a');
      if (j == d || ((k & (1 << (w[j + 1] - 'a'))) == 0) && GGG[k] == 1) {
        HH[k]++;
      }
    }
  }
  for (i = 1; i <= a; i++) printf("%d\n", HH[G[i]]);
  return 0;
}
