#include <bits/stdc++.h>
using namespace std;
struct node {
  int fail;
  bool vis;
  map<char, int> nxt;
};
vector<node> trie;
string input() {
  static char buf[1000010];
  buf[0] = 0;
  scanf("%s", buf);
  return buf;
}
int main() {
  trie.emplace_back();
  trie[0].fail = -1;
  string t = input();
  int q;
  scanf("%d", &q);
  vector<int> idx(q);
  for (int i = 0; i < q; ++i) {
    string p = input();
    int u = 0;
    for (char c : p) {
      if (!trie[u].nxt.count(c)) {
        trie[u].nxt.emplace(c, trie.size());
        trie.emplace_back();
      }
      u = trie[u].nxt[c];
    }
    idx[i] = u;
  }
  vector<int> bfs;
  bfs.push_back(0);
  int k = 0;
  while (k < (int)bfs.size()) {
    int u = bfs[k++];
    for (const auto &pr : trie[u].nxt) {
      char c = pr.first;
      int v = pr.second;
      bfs.push_back(v);
      int f = trie[u].fail;
      while (f >= 0 && !trie[f].nxt.count(c)) {
        f = trie[f].fail;
      }
      trie[v].fail = f >= 0 ? trie[f].nxt[c] : 0;
    }
  }
  int r = 0;
  for (char c : t) {
    while (r >= 0 && !trie[r].nxt.count(c)) {
      r = trie[r].fail;
    }
    r = r >= 0 ? trie[r].nxt[c] : 0;
    trie[r].vis = true;
  }
  for (int i = bfs.size(); i--;) {
    int u = bfs[i];
    if (trie[u].vis) {
      trie[trie[u].fail].vis = true;
    }
  }
  for (int i = 0; i < q; ++i) {
    printf("%d\n", +trie[idx[i]].vis);
  }
}
