#include <bits/stdc++.h>
using namespace std;
using ll = long long;
class Aho_Corasick {
  struct node {
    node *no;
    vector<node *> next;
    vector<int> matched;
    node() : no(nullptr), next(128, nullptr) {}
    ~node() {
      for (auto ite : next)
        if (ite != nullptr) delete ite;
    }
  };
  vector<int> unite(const vector<int> &a, const vector<int> &b) {
    vector<int> res;
    set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res));
    return res;
  }
  int K;
  node *root;

 public:
  Aho_Corasick(const vector<string> &Ts) : K(Ts.size()), root(new node) {
    node *now;
    root->no = root;
    for (int i = 0; i < K; i++) {
      auto &T = Ts[i];
      now = root;
      for (auto c : T) {
        if (now->next[c] == nullptr) {
          now->next[c] = new node;
        }
        now = now->next[c];
      }
      now->matched.push_back(i);
    }
    queue<node *> q;
    for (int i = 0; i < 128; i++) {
      if (root->next[i] == nullptr) {
        root->next[i] = root;
      } else {
        root->next[i]->no = root;
        q.push(root->next[i]);
      }
    }
    while (!q.empty()) {
      now = q.front();
      q.pop();
      for (int i = 0; i < 128; i++) {
        if (now->next[i] != nullptr) {
          node *nx = now->no;
          while (nx->next[i] == nullptr) {
            nx = nx->no;
          }
          now->next[i]->no = nx->next[i];
          now->next[i]->matched =
              unite(now->next[i]->matched, nx->next[i]->matched);
          q.push(now->next[i]);
        }
      }
    }
  }
  vector<int> count(const string &S) {
    vector<int> res(K);
    node *now = root;
    for (auto c : S) {
      while (now->next[c] == nullptr) {
        now = now->no;
      }
      now = now->next[c];
      for (auto k : now->matched) {
        res[k]++;
      }
    }
    return res;
  }
};
int main() {
  string S;
  int M;
  cin >> S >> M;
  vector<string> C(M);
  for (int i = 0; i < M; i++) {
    cin >> C[i];
  }
  Aho_Corasick aho(C);
  auto cnt = aho.count(S);
  for (auto t : cnt) {
    cout << (t != 0) << endl;
  }
  return 0;
}
