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