#include <bits/stdc++.h>
using namespace std;
bool str_match(std::string, std::string);
int main() {
  std::string str;
  std::string ptn;
  getline(cin, str);
  int n;
  int result[10000];
  string nl;
  cin >> n;
  getline(cin, nl);
  for (int times = 0; times < n; times++) {
    getline(cin, ptn);
    if (str_match(str, ptn)) {
      result[times] = 1;
    } else {
      result[times] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << result[i] << "\n";
  }
}
bool str_match(std::string str, std::string ptn) {
  bool matched = true;
  int i = 0;
  while (i < str.length()) {
    matched = true;
    for (int j = 0; j < ptn.length(); j++) {
      if (str[i + j] != ptn[j]) {
        matched = false;
        break;
      }
    }
    if (matched) break;
    i++;
  }
  return matched;
}
