#include <bits/stdc++.h>
using namespace std;
bool searchText(const char t1[], const char t2[]);
bool compareText(const char *t1, char const *t2, int len);
int main(void) {
  char t[1000000 + 1] = "\0";
  cin >> t;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    char p[1000 + 1] = "\0";
    cin >> p;
    cout << (int)searchText(t, p) << endl;
  }
  return 0;
}
bool searchText(const char t1[], const char t2[]) {
  int t1_len = strlen(t1);
  int t2_len = strlen(t2);
  if (t1_len < t2_len) return false;
  for (int i = 0; i + t2_len <= t1_len; i++) {
    if (compareText(&t1[i], t2, t2_len)) return true;
  }
  return false;
}
bool compareText(const char *t1, const char *t2, int len) {
  for (int i = 0; i < len; i++) {
    if (*(t1 + i) != *(t2 + i)) return false;
  }
  return true;
}
