#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];
int SA[N_MAX];
int Rank[N_MAX];
int tmp[N_MAX];
int k;
int Q;
char* P[M_MAX];
vector<int> placeOfP[M_MAX];
bool compare_sa(int i, int j) {
  if (Rank[i] != Rank[j])
    return Rank[i] < Rank[j];
  else {
    int rank_i = (i + k < N ? Rank[i + k] : -1);
    int rank_j = (j + k < N ? Rank[j + k] : -1);
    return rank_i < rank_j;
  }
}
void construct_sa() {
  k = 1;
  for (int(i) = (0); (i) < (N); (i)++) {
    SA[i] = i;
    Rank[i] = T[i];
  }
  for (k = 1; k < N; k *= 2) {
    sort(SA, SA + N, compare_sa);
    tmp[SA[0]] = 0;
    for (int(i) = (1); (i) < (N); (i)++) {
      tmp[SA[i]] = tmp[SA[i - 1]] + compare_sa(SA[i - 1], SA[i]);
    }
    for (int(i) = (0); (i) < (N); (i)++) Rank[i] = tmp[i];
  }
}
void binarySearch_P_from_SA() {
  for (int(i) = (0); (i) < (Q); (i)++) {
    int lenP = strlen(P[i]);
    int left = 0;
    int right = N - 1;
    int mid;
    while (left <= right) {
      mid = left + (right - left) / 2;
      if (strncmp(P[i], T + SA[mid], lenP) == 0) {
        placeOfP[i].push_back(SA[mid]);
        break;
      } else if (strncmp(P[i], T + SA[mid], lenP) < 0)
        right = mid - 1;
      else
        left = mid + 1;
    }
    int k = mid - 1;
    while (k > 0 && strncmp(P[i], T + SA[k], lenP) == 0) {
      placeOfP[i].push_back(SA[k]);
      k--;
    }
    k = mid + 1;
    while (k < N && strncmp(P[i], T + SA[k], lenP) == 0) {
      placeOfP[i].push_back(SA[k]);
      k++;
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  scanf("%s", T);
  N = strlen(T);
  scanf("%d ", &Q);
  for (int(i) = (0); (i) < (Q); (i)++) {
    P[i] = (char*)malloc(sizeof(char) * DATA_MAX);
    scanf("%s", P[i]);
  }
  construct_sa();
  binarySearch_P_from_SA();
  for (int(i) = (0); (i) < (Q); (i)++) {
    printf("%d\n", placeOfP[i].size() != 0);
  }
  return 0;
}
