#include <bits/stdc++.h>
using namespace std;
string t;
int q, n, size;
bool flag;
int id[70] = {};
int main() {
  cin >> t >> q;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] > 'a' && t[i] < 'Z')
      id[t[i] - 'a']++;
    else
      id[52 + t[i] - '0']++;
  }
  for (int i = 0; i < q; i++) {
    flag = false;
    int z[70] = {};
    string p;
    cin >> p;
    size = p.size();
    for (int h = 0; h < size; h++) {
      if (t[h] > 'a' && t[h] < 'Z')
        id[t[h] - 'a']++;
      else
        z[52 + t[h] - '0']++;
    }
    for (int w = 0; w < 70; w++)
      if (id[w] != z[w]) flag = true;
    if (flag) continue;
    for (int j = 0; j < t.size(); j++) {
      if (t[j] == p[0]) {
        if (size == 1) {
          cout << 1 << endl;
          flag = true;
        }
        for (int k = 1; k < size; k++) {
          if (t[j + k] != p[k]) break;
          if (k == size - 1) {
            cout << 1 << endl;
            flag = true;
          }
        }
      }
      if (flag) break;
    }
    if (!flag) cout << 0 << endl;
  }
  return 0;
}
