#include <bits/stdc++.h>
using namespace std;
static const unsigned long long B = 100000007;
bool contain(string a, string b) {
  int al = a.length(), bl = b.length();
  if (al > bl) return false;
  unsigned long long t = 1;
  for (int i = 0; i < al; i++) t *= B;
  unsigned long long ah = 0, bh = 0;
  for (int i = 0; i < al; i++) ah = ah * B + a[i];
  for (int i = 0; i < al; i++) bh = bh * B + b[i];
  for (int i = 0; i + al <= bl; i++) {
    if (ah == bh) return true;
    if (i + al < bl) bh = bh * B + b[i + al] - b[i] * t;
  }
  return false;
}
int main() {
  int Q;
  string a, b;
  cin >> a;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> b;
    cout << (contain(b, a) ? "1" : "0") << endl;
  }
  return 0;
}
