#include <bits/stdc++.h>
using namespace std;
const int MAX_ALP = 26;
const int MAX_SIZE = 10000000 + 7;
struct Node {
  vector<int> go;
  char c;
  int f;
  bool b;
  vector<string> text;
  Node() {
    c = ' ';
    f = -1;
    b = false;
    go.resize(MAX_ALP, -1);
  }
};
vector<Node> G;
int sz = 1;
int idx(char c) { return c - 'a'; }
void make_trie(vector<string> W) {
  int ws = W.size();
  int now = 0;
  int sz = 1;
  for (int i = 0; i < ws; i++) {
    now = 0;
    string s = W[i];
    for (int k = 0; k < s.length(); k++) {
      if (G[now].go[idx(s[k])] == -1) {
        Node node;
        node.c = s[k];
        G.push_back(node);
        G[now].go[idx(s[k])] = sz;
        now = sz++;
      } else {
        now = G[now].go[idx(s[k])];
      }
      if (k + 1 == s.length()) {
        G[now].text.push_back(s);
        G[now].b = true;
      }
    }
  }
}
int back_failure(int t, char c) {
  while (G[t].go[c] == -1) {
    t = G[t].f;
  }
  return G[t].go[c];
}
void make_failure() {
  queue<int> que;
  for (int i = 0; i < MAX_ALP; i++) {
    int nx = G[0].go[i];
    if (nx != -1) {
      G[nx].f = 0;
      que.push(nx);
    } else {
      G[0].go[i] = 0;
    }
  }
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (int i = 0; i < MAX_ALP; i++) {
      if (G[now].go[i] != -1) {
        que.push(G[now].go[i]);
        int p = back_failure(G[now].f, i);
        int s = G[now].go[i];
        G[s].f = p;
        if (G[p].b) {
          G[s].b = true;
          G[s].text.insert(G[s].text.end(), G[p].text.begin(), G[p].text.end());
        }
      }
    }
  }
}
vector<pair<string, pair<int, int> > > match(string st) {
  vector<pair<string, pair<int, int> > > ret;
  int now = 0;
  for (int i = 0; i < st.length(); i++) {
    int id = idx(st[i]);
    while (G[now].go[id] == -1) {
      now = G[now].f;
    }
    now = G[now].go[id];
    for (int k = 0; k < G[now].text.size(); k++) {
      string s = G[now].text[k];
      ret.push_back(make_pair(s, make_pair((i + 1) - s.length(), i)));
    }
  }
  return ret;
}
int main() {
  string text;
  cin >> text;
  int n;
  cin >> n;
  Node root;
  root.c = '*';
  root.f = 0;
  G.push_back(root);
  vector<string> words(n);
  for (int i = 0; i < n; i++) cin >> words[i];
  make_trie(words);
  make_failure();
  vector<pair<string, pair<int, int> > > ans = match(text);
  set<string> s;
  for (int i = 0; i < ans.size(); i++) s.insert(ans[i].first);
  for (int i = 0; i < words.size(); i++) {
    if (s.find(words[i]) != s.end())
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
