#include <bits/stdc++.h>
using namespace std;
struct Node {
  Node* child[256];
  vector<int> output;
  Node() { memset(child, 0, sizeof(child)); }
  ~Node() {
    for (int i = 0; i < 256; i++)
      if (child[i]) delete child[i];
  }
};
void concatIntVector(vector<int>& v1, vector<int>& v2) {
  v1.insert(v1.begin(), v2.begin(), v2.end());
}
Node* makePMA(vector<string>& P) {
  Node* root = new Node;
  root->child[0] = 0;
  Node* now;
  for (int i = 0; i < P.size(); i++) {
    now = root;
    for (int j = 0; j < P[i].size(); j++) {
      if (now->child[(int)P[i][j]] == 0) {
        now->child[(int)P[i][j]] = new Node;
      }
      now = now->child[(int)P[i][j]];
    }
    now->output.push_back(i);
  }
  queue<Node*> qu;
  for (int i = 1; i < 256; i++) {
    if (root->child[i]) {
      root->child[i]->child[0] = root;
      qu.push(root->child[i]);
    } else {
      root->child[i] = root;
    }
  }
  while (!qu.empty()) {
    now = qu.front();
    qu.pop();
    for (int i = 1; i < 256; i++) {
      if (now->child[i]) {
        Node* fail = now->child[0];
        while (!fail->child[i]) {
          fail = fail->child[0];
        }
        now->child[i]->child[0] = fail->child[i];
        concatIntVector(now->child[i]->output, fail->child[i]->output);
        qu.push(now->child[i]);
      }
    }
  }
  return root;
}
void searchPMA(Node*& root, string& T, vector<bool>& res) {
  Node* now = root;
  for (int i = 0; i < T.size(); i++) {
    while (!now->child[(int)T[i]]) {
      now = now->child[0];
    }
    now = now->child[(int)T[i]];
    for (int j = 0; j < (now->output).size(); j++) {
      res[(now->output)[j]] = true;
    }
  }
  return;
}
int main() {
  string T;
  cin >> T;
  int Q;
  cin >> Q;
  vector<string> P;
  string tmp;
  for (int i = 0; i < Q; i++) {
    cin >> tmp;
    P.push_back(tmp);
  }
  Node* root = makePMA(P);
  vector<bool> res(Q, false);
  searchPMA(root, T, res);
  for (int i = 0; i < res.size(); i++) {
    cout << res[i] << endl;
  }
  return 0;
}
