#include <bits/stdc++.h>
using namespace std;
struct charnode {
  vector<int> index;
  map<char, charnode> child;
  charnode() : index(), child() {}
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string t, temp;
  int n;
  charnode wordlist;
  getline(cin, t);
  cin >> n;
  cin.ignore();
  for (int i = 0; i < n; i++) {
    getline(cin, temp);
    charnode *p = &wordlist;
    for (int j = 0, len = temp.length(); j < len; j++) {
      p = &(p->child[temp[j]]);
    }
    p->index.push_back(i);
  }
  int res[10000] = {};
  int len = t.length();
  for (int i = 0; i < len; i++) {
    charnode *p = &wordlist;
    for (int j = i; j < len; j++) {
      map<char, charnode>::iterator it = p->child.find(t[j]);
      if (it == p->child.end()) break;
      p = &(it->second);
      for (vector<int>::iterator t = p->index.begin(); t != p->index.end();
           ++t) {
        res[*t] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) cout << res[i] << '\n';
  return 0;
}
