#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int Q;
char STR1[1000001], STR2[1001];
vector<int> ptr[62];
const char strings[63] =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
int main() {
  scanf("%s", &STR1);
  for (int i = 0; i < strlen(STR1); i++) {
    for (int j = 0; j < 62; j++) {
      if (STR1[i] == strings[j]) {
        ptr[j].push_back(i);
        break;
      }
    }
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%s", STR2);
    int code_;
    int size_;
    for (int j = 0; j < 62; j++) {
      if (STR2[0] == strings[j]) {
        size_ = ptr[j].size();
        code_ = j;
      }
    }
    for (int j = 0; j < size_; j++) {
      int ptr_ = ptr[code_][j];
      bool ok = false;
      if (ptr[code_][j] + strlen(STR2) <= strlen(STR1)) {
        ok = true;
        for (int k = 0; k < strlen(STR2); k++) {
          if (STR1[ptr_ + k] != STR2[k]) {
            ok = false;
            break;
          }
        }
      }
      if (ok) {
        printf("1\n");
        goto Exit;
      }
      if (j + 1 >= size_) {
        printf("0\n");
      }
    }
    if (size_ == 0) {
      printf("0\n");
    }
  Exit:;
  }
  return 0;
}
