#include <bits/stdc++.h>
using namespace std;
const unsigned long long B = 100000007;
unsigned long long thash[1001];
unsigned long long BB[1001];
string T;
int bl;
bool contain(string a) {
  int al = a.length();
  unsigned long long t;
  unsigned long long ah = 0, bh = 0;
  for (int i = 0; i < al; i++) ah = ah * B + a[i];
  bh = thash[al];
  t = BB[al];
  for (int i = 0; i + al <= bl; i++) {
    if (ah == bh) return true;
    bh = bh * B + T[i + al] - T[i] * t;
  }
  return false;
}
int main() {
  int k;
  bool ans;
  string P;
  cin >> T;
  bl = T.length();
  thash[0] = 0;
  for (int i = 1; i <= 1000; i++) thash[i] = thash[i - 1] * B + T[i - 1];
  BB[0] = 1;
  for (int i = 1; i <= 1000; i++) BB[i] = BB[i - 1] * B;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    cin >> P;
    if (T.size() >= P.size()) {
      ans = contain(P);
      if (ans)
        printf("1\n");
      else
        printf("0\n");
    }
  }
}
