#include <bits/stdc++.h>
using namespace std;
int main() {
  string T, P;
  int Q, check;
  cin >> T;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> P;
    check = 0;
    if (T.length() >= P.length())
      for (int j = 0; j <= T.length() - P.length(); j++)
        if (T.substr(j, P.length()) == P) {
          check++;
          break;
        }
    printf("%d\n", check);
  }
  return 0;
}
