#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, -1, 1, -1, 1, 1, -1};
const int INF = (int)2e9 + 10;
const long long INF_LL = (long long)9e18 - 1LL;
const unsigned long INF_ULL = (unsigned long)1e19 - 1ULL;
const int NONE = -1;
const long long MOD = (long long)1e9 + 7;
const int N_MAX = 1000010;
const int M_MAX = 10010;
const int DATA_MAX = 1010;
int N;
char T[N_MAX];
char* P[M_MAX];
vector<int> placeOfP[M_MAX];
struct PMA {
  PMA* next[128];
  vector<int> accept;
  PMA() { fill(next, next + 128, (PMA*)0); }
};
vector<int> set_union(const vector<int>& a, const vector<int>& b) {
  vector<int> res;
  set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res));
  return res;
}
PMA* buildPMA(char* P[], int numOfP) {
  PMA* root = new PMA;
  for (int(i) = (0); (i) < (numOfP); (i)++) {
    PMA* t = root;
    for (int j = 0; P[i][j]; j++) {
      char c = P[i][j];
      if (t->next[c] == NULL) {
        t->next[c] = new PMA;
      }
      t = t->next[c];
    }
    t->accept.push_back(i);
  }
  queue<PMA*> Q;
  for (int(c) = ('0'); (c) < ('z' + 1); (c)++) {
    if (root->next[c] != NULL) {
      root->next[c]->next[0] = root;
      Q.push(root->next[c]);
    } else
      root->next[c] = root;
  }
  while (!Q.empty()) {
    PMA* now = Q.front();
    Q.pop();
    for (int(c) = ('0'); (c) < ('z' + 1); (c)++) {
      if (now->next[c] != NULL) {
        Q.push(now->next[c]);
        PMA* failure = now->next[0];
        while (failure->next[c] == NULL) failure = failure->next[0];
        now->next[c]->next[0] = failure->next[c];
        now->next[c]->accept =
            set_union(now->next[c]->accept, failure->next[c]->accept);
      }
    }
  }
  return root;
}
void match(PMA* v, char* text, vector<int> result[]) {
  int lenT = strlen(text);
  for (int(i) = (0); (i) < (lenT); (i)++) {
    char c = text[i];
    while (v->next[c] == NULL) {
      v = v->next[0];
    }
    v = v->next[c];
    for (int(j) = (0); (j) < (v->accept.size()); (j)++) {
      result[v->accept[j]].push_back(i + 1 - strlen(P[v->accept[j]]));
    }
  }
  return;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  scanf("%s", T);
  int Q;
  scanf("%d ", &Q);
  for (int(i) = (0); (i) < (Q); (i)++) {
    P[i] = (char*)malloc(sizeof(char) * DATA_MAX);
    scanf("%s", P[i]);
  }
  PMA* root = buildPMA(P, Q);
  match(root, T, placeOfP);
  for (int(i) = (0); (i) < (Q); (i)++) {
    printf("%d\n", placeOfP[i].size() != 0);
  }
  return 0;
}
