#include <bits/stdc++.h>
using namespace std;
int main() {
  string T;
  cin >> T;
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    string P;
    cin >> P;
    if (T.find(P) == string::npos)
      cout << 0 << endl;
    else
      cout << 1 << endl;
  }
  return 0;
}
