#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 = 1000000;
const int M_MAX = 100000;
const int DATA_MAX = 1000000010;
int N;
char T[N_MAX];
char P[10010][1010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int i = 0;
  while (1) {
    scanf("%c", &T[i]);
    if (T[i] == '\n') {
      T[i] = '\0';
      break;
    } else
      i++;
  }
  int Q;
  scanf("%d ", &Q);
  for (int(i) = (0); (i) < (Q); (i)++) {
    int j = 0;
    while (1) {
      scanf("%c", &P[i][j]);
      if (P[i][j] == '\n') {
        P[i][j] = '\0';
        break;
      } else
        j++;
    }
  }
  int lenT = strlen(T);
  const int B = 10007;
  for (int(i) = (0); (i) < (Q); (i)++) {
    int lenP = strlen(P[i]);
    int BpowLenP = 1;
    for (int(k) = (0); (k) < (lenP); (k)++) BpowLenP *= B;
    int hashP = 0;
    for (int(k) = (0); (k) < (lenP); (k)++) hashP = hashP * B + P[i][k];
    int hashT = 0;
    for (int(k) = (0); (k) < (lenP); (k)++) hashT = hashT * B + T[k];
    bool found = false;
    for (int(j) = (0); (j) < (lenT - lenP + 1); (j)++) {
      if (hashP == hashT) {
        found = true;
        break;
      }
      if (j + lenP < lenT) hashT = hashT * B - T[j] * BpowLenP + T[j + lenP];
    }
    printf("%d\n", found);
  }
  return 0;
}
