#include <bits/stdc++.h>
using namespace std;
using LL = int;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
struct Tll {
  LL first, second, third;
};
struct Fll {
  LL first, second, third, fourd;
};
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, dp[100], a[20000], b[20000];
string str, ss;
bool f[1100];
char c;
int di[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
struct Edge {
  LL to, cost;
};
vector<Edge> vec[100];
vector<LL> v;
pair<string, LL> sa[1000000];
map<string, vector<LL>> ma;
multiset<LL> st;
void YN(bool f) {
  if (f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void yn(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void compare() {
  string ss = "";
  sa[0] = make_pair(ss, str.size());
  for (int i = 0; i < str.size(); i++) {
    ss = str[str.size() - i - 1] + ss;
    sa[i + 1] = make_pair(ss, str.size() - i - 1);
  }
  sort(sa, sa + str.size() + 1);
}
int main() {
  cin >> str;
  compare();
  cin >> q;
  for (LL i = 0; i < q; i++) {
    cin >> ss;
    int l = 0, r = str.size();
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (str.compare(sa[m].second, ss.size(), ss) < 0)
        l = m;
      else
        r = m;
    }
    cout << (str.compare(sa[r].second, ss.size(), ss) == 0) << endl;
  }
  return 0;
}
