#include <bits/stdc++.h>
using namespace std;
int checkTable[10000] = {0};
struct LocInfo {
  char* pointer;
  int pattern_index;
  bool used;
};
struct Node {
  Node() {
    num_of_outputed_info = num_of_finish_info = 0;
    exitstFLG = false;
  }
  vector<LocInfo> finish_info_bank;
  int num_of_finish_info;
  int num_of_outputed_info;
  bool exitstFLG;
};
int charNUM(char ch) {
  if (ch >= '0' && ch < '9') {
    return ch - 48;
  } else if (ch >= 'A' && ch <= 'Z') {
    return ch - 55;
  } else {
    return ch - 61;
  }
}
int main() {
  Node** nodes = new Node*[1000];
  for (int i = 0; i < 1000; i++) {
    nodes[i] = new Node[62];
  }
  char* T = new char[1000001];
  int Q, T_length = 0, index, limit;
  scanf("%s", T);
  scanf("%d", &Q);
  char** P = new char*[Q];
  for (int i = 0; i < Q; i++) {
    P[i] = new char[1001];
    scanf("%s", P[i]);
    index = 0;
    while (P[i][index + 1] != '\0') {
      nodes[index][charNUM(P[i][index])].exitstFLG = true;
      index++;
    }
    LocInfo info;
    info.pointer = P[i];
    info.pattern_index = i;
    info.used = false;
    nodes[index][charNUM(P[i][index])].exitstFLG = true;
    nodes[index][charNUM(P[i][index])].finish_info_bank.push_back(info);
    nodes[index][charNUM(P[i][index])].num_of_finish_info++;
  }
  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 (nodes[k][charNUM(T[i + k])].exitstFLG == true) {
        if ((limit = nodes[k][charNUM(T[i + k])].num_of_finish_info) > 0) {
          for (int search = 0; search < limit; search++) {
            if (nodes[k][charNUM(T[i + k])].finish_info_bank[search].used ==
                    false &&
                strcmp(nodes[k][charNUM(T[i + k])]
                           .finish_info_bank[search]
                           .pointer,
                       tmp) == 0) {
              checkTable[nodes[k][charNUM(T[i + k])]
                             .finish_info_bank[search]
                             .pattern_index] = 1;
              nodes[k][charNUM(T[i + k])].finish_info_bank[search].used = true;
              if (++nodes[k][charNUM(T[i + k])].num_of_outputed_info ==
                  nodes[k][charNUM(T[i + k])].num_of_finish_info) {
                nodes[k][charNUM(T[i + k])].num_of_finish_info = 0;
              }
            }
          }
        }
      } else {
        break;
      }
    }
  }
  for (int i = 0; i < Q; i++) {
    if (checkTable[i] == 0)
      printf("0\n");
    else {
      printf("1\n");
    }
  }
  return 0;
}
