#include <bits/stdc++.h>
using namespace std;
template <typename T>
class PMA {
 private:
  uint32_t id = 0;
  uint32_t pattern = 0;

 public:
  struct Node {
    uint32_t id;
    vector<uint32_t> accept;
    unordered_map<T, Node *> children;
    Node *failure = nullptr;
  };
  Node *root;
  int32_t insert(const vector<T> &vec) {
    Node *node = root;
    for (T v : vec) {
      auto itr = node->children.find(v);
      if (itr != node->children.end()) {
        node = itr->second;
      } else {
        node->children[v] = new Node;
        node->children[v]->id = id++;
        node = node->children[v];
      }
    }
    node->accept.push_back(pattern++);
    return node->id;
  }
  Node *transition(Node *node, T v) {
    while (node != nullptr) {
      auto itr = node->children.find(v);
      if (itr != node->children.end()) {
        return itr->second;
      } else {
        node = node->failure;
      }
    }
    return root;
  }
  void link_failure() {
    queue<Node *> tovisit;
    tovisit.push(root);
    while (!tovisit.empty()) {
      Node *node = tovisit.front();
      tovisit.pop();
      for (auto p : node->children) {
        T v = p.first;
        Node *child = p.second;
        child->failure = transition(node->failure, v);
        for (uint32_t a : child->failure->accept) child->accept.push_back(a);
        tovisit.push(child);
      }
    }
    return;
  }
  PMA() {
    root = new Node;
    root->id = id++;
  }
};
int main() {
  vector<uint8_t> T;
  string temp;
  cin >> temp;
  T = vector<uint8_t>(temp.begin(), temp.end());
  int32_t Q;
  cin >> Q;
  vector<vector<uint8_t>> P(Q);
  for (int32_t i = 0; i < Q; i++) {
    string temp;
    cin >> temp;
    P[i] = vector<uint8_t>(temp.begin(), temp.end());
  }
  PMA<uint8_t> pma;
  for (vector<uint8_t> vec : P) pma.insert(vec);
  pma.link_failure();
  vector<bool> result(Q, false);
  PMA<uint8_t>::Node *node = pma.root;
  for (uint8_t c : T) {
    node = pma.transition(node, c);
    for (uint32_t a : node->accept) result[a] = true;
  }
  for (bool b : result) cout << (b ? "1" : "0") << endl;
  return 0;
}
