#include <bits/stdc++.h>
using namespace std;
struct node {
  node* fail;
  unordered_map<char, node*> next;
  vector<int> ok;
  node() : fail(nullptr) {}
};
node* getnext(node* p, char c) {
  while (p->next.count(c) == 0) p = p->fail;
  return p->next[c];
}
class aho_corasick {
  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->fail = 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->ok.push_back(i);
    }
    queue<node*> q;
    for (auto p : root->next) {
      if (p.second) {
        p.second->fail = root;
        q.push(p.second);
      }
    }
    while (!q.empty()) {
      now = q.front();
      q.pop();
      for (auto p : now->next) {
        if (p.second) {
          node* nx = now->fail;
          while (nx != root && !nx->next.count(p.first)) {
            nx = nx->fail;
          }
          if (!nx->next.count(p.first)) nx->next[p.first] = root;
          p.second->fail = nx->next[p.first];
          p.second->ok = unite(p.second->ok, nx->next[p.first]->ok);
          q.push(p.second);
        }
      }
    }
  }
  node* getroot() const { return root; }
  vector<int> count(const string& S) const {
    vector<int> res(K);
    node* now = root;
    for (auto c : S) {
      now = getnext(now, c);
      for (auto k : now->ok) res[k] = 1;
    }
    return res;
  }
};
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  string T;
  cin >> T;
  int Q;
  cin >> Q;
  vector<string> P(Q);
  for (int i = 0; i < Q; i++) {
    cin >> P[i];
  }
  aho_corasick ac(P);
  auto res = ac.count(T);
  for (auto b : res) {
    printf("%d\n", b);
  }
  return 0;
}
