#include <bits/stdc++.h>
using namespace std;
int checkTable[10000] = {0};
class Node {
 public:
  Node() {
    ch = 0;
    num_of_child = num_of_end_str = 0;
    parent = 0;
    cameFLG = false;
    table = new short[128 - 48];
    for (int i = 48; i <= 122; i++) table[i - 48] = -1;
  }
  void addSTR(char str[], int ptn_index) {
    int index = 0;
    Node* tmp = this;
    while (true) {
      if (str[index + 1] == '\0') {
        tmp->end_str.push_back(ptn_index);
        tmp->num_of_end_str++;
        break;
      } else {
        if (tmp->table[str[index + 1] - 48] == -1) {
          Node* new_node = new Node();
          new_node->parent = tmp;
          new_node->ch = str[index + 1];
          tmp->nodes.push_back(new_node);
          tmp->table[str[index + 1] - 48] = tmp->num_of_child;
          tmp->num_of_child++;
        }
        tmp = tmp->nodes[tmp->table[str[index + 1] - 48]];
        index++;
      }
    }
  }
  bool searchSTR(char str[], int index) {
    Node* tmp = this;
    while (true) {
      if (!tmp->cameFLG) {
        for (int i = 0; i < tmp->num_of_end_str; i++)
          checkTable[tmp->end_str[i]] = 1;
        tmp->cameFLG = true;
      }
      if (tmp->num_of_child == 0) {
        if (tmp->parent != 0) {
          Node* parent = tmp->parent;
          parent->num_of_child--;
          parent->table[tmp->ch - 48] = -1;
          while (parent->parent != 0 && parent->num_of_child == 0) {
            parent->parent->num_of_child--;
            parent->parent->table[parent->ch - 48] = -1;
            parent = parent->parent;
          }
        }
        return false;
      } else {
        if (str[index + 1] == '\0')
          return true;
        else {
          if (tmp->table[str[index + 1] - 48] != -1) {
            tmp = tmp->nodes[tmp->table[str[index + 1] - 48]];
            index++;
          } else {
            return false;
          }
        }
      }
    }
    return false;
  }
  short num_of_child;
  short num_of_end_str;
  vector<short> end_str;
  vector<Node*> nodes;
  Node* parent;
  short* table;
  char ch;
  bool cameFLG;
};
class MotherNode {
 public:
  MotherNode() {
    motherNode = new Node*[128 - 48];
    for (int i = 48; i <= 122; i++) {
      motherNode[i - 48] = new Node();
      motherNode[i - 48]->ch = i;
    }
  }
  void addSTR(char str[], int ptn_index) {
    motherNode[str[0] - 48]->addSTR(str, ptn_index);
  }
  bool searchSTR(char str[]) {
    return motherNode[str[0] - 48]->searchSTR(str, 0);
  }

 private:
  Node** motherNode;
};
int main() {
  char* T = new char[1000001];
  int Q, T_length = 0;
  scanf("%s", T);
  scanf("%d", &Q);
  char* P = new char[1001];
  MotherNode motherNode;
  for (int i = 0; i < Q; i++) {
    scanf("%s", P);
    motherNode.addSTR(P, i);
  }
  for (int i = 0; T[i] != '\0'; i++) T_length++;
  char tmp[1001];
  for (int i = 0; i < T_length; i++) {
    for (int k = 0; k < 1001; k++) tmp[k] = '\0';
    for (int k = 0; T[i + k] != '\0' && k < 1000; k++) {
      tmp[k] = T[i + k];
      if (motherNode.searchSTR(tmp) == false) break;
    }
  }
  for (int i = 0; i < Q; i++) {
    if (checkTable[i] == 0)
      printf("0\n");
    else {
      printf("1\n");
    }
  }
  return 0;
}
