#include <bits/stdc++.h>
using namespace std;
unsigned long long B = 100000007;
int h[1001] = {};
set<unsigned long long> s[1001];
void contain(string b, int n) {
  int bl = b.size();
  unsigned long long t = 1;
  for (int i = 0; i < n; i++) t *= B;
  unsigned long long bh = 0;
  for (int i = 0; i < n; i++) bh = bh * B + b[i];
  for (int i = 0; i + n <= bl; i++) {
    s[n].insert(bh);
    if (i + n < bl) bh = bh * B + b[i + n] - b[i] * t;
  }
  return;
}
int main() {
  int n;
  string b;
  cin >> b >> n;
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    int al = a.size();
    if (al > b.size()) {
      cout << '0' << endl;
      continue;
    }
    if (h[al] == 0) {
      contain(b, al);
      h[al] = 1;
    }
    unsigned long long ah = 0;
    for (int j = 0; j < al; j++) ah = ah * B + a[j];
    cout << s[al].count(ah) << endl;
  }
  return 0;
}
