#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
bool d[1 << 26];
string str;
int N;
int ar[10000 + 1], K[128];
int main() {
  string s;
  cin >> str;
  int i, j, k, t;
  scanf(" %d", &N);
  for (i = 1; i <= N; i++) {
    k = 0;
    cin >> s;
    for (j = 0; j < s.size(); j++) k = k | (1 << (s[j] - 'a'));
    ar[i] = k;
    d[k] = 1;
  }
  int bas, son, c;
  for (t = 1; t <= 26; t++) {
    bas = 0;
    son = 0;
    c = 1;
    k = 1 << (str[son] - 'a');
    for (i = 'a'; i <= 'z'; i++) K[i] = 0;
    K[str[son]] = 1;
    while (1) {
      while (son + 1 < str.size() && (K[str[son + 1]] || c < t)) {
        if (K[str[son + 1]]++)
          son++;
        else {
          son++;
          c++;
          k |= 1 << (str[son] - 'a');
        }
      }
      if (c < t) break;
      if (d[k]) mp[k]++;
      while (c == t) {
        if (K[str[bas]] > 1)
          K[str[bas++]]--;
        else {
          K[str[bas]]--;
          k &= ~(1 << (str[bas] - 'a'));
          c--;
          bas++;
        }
      }
    }
  }
  for (i = 0; ++i <= N;) printf("%d\n", mp[ar[i]]);
  return 0;
}
