#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
#define NUM 48
using namespace std;

int T_char_count[128] = {0},P_char_count[128];

class LocRecord{

public:
	//?????¢???????¢????
	LocRecord(){
		locationTable = new int*[128];
		for(int i = 48; i <= 57; i++){
			if(T_char_count[i] > 0){
				locationTable[i] = new int[T_char_count[i]+1];
			}else{
				locationTable[i] = new int[2];
			}
		}
		for(int i = 65; i <= 90; i++){
			if(T_char_count[i] > 0){
				locationTable[i] = new int[T_char_count[i]+1];
			}else{
				locationTable[i] = new int[2];
			}
		}
		for(int i = 97; i <= 122; i++){
			if(T_char_count[i] > 0){
				locationTable[i] = new int[T_char_count[i]+1];
			}else{
				locationTable[i] = new int[2];
			}
		}
	}

	//-1?????£??\
	void init(){
		int limit;
		for(int i = 48; i <= 57; i++){
			limit = T_char_count[i];
			if(T_char_count[i] > 0){
				index[i] = 0;

				for(int k = 0; k <= limit; k++){
					locationTable[i][k] = -1;
				}
			}else{
				index[i] = 0;
				locationTable[i][0] = -1;
			}
		}
		for(int i = 65; i <= 90; i++){
			limit = T_char_count[i];
			if(T_char_count[i] > 0){
				index[i] = 0;

				for(int k = 0; k <= limit; k++){
					locationTable[i][k] = -1;
				}
			}else{
				index[i] = 0;
				locationTable[i][0] = -1;
			}
		}
		for(int i = 97; i <= 122; i++){
			limit = T_char_count[i];
			if(T_char_count[i] > 0){
				index[i] = 0;
				for(int k = 0; k <= limit; k++){
					locationTable[i][k] = -1;
				}
			}else{
				index[i] = 0;
				locationTable[i][0] = -1;
			}
		}
	}

	void init_index(){
		for(int i = 48; i <= 57; i++){
			index[i] = 0;
		}
		for(int i = 65; i <= 90; i++){
			index[i] = 0;
		}
		for(int i = 97; i <= 122; i++){
			index[i] = 0;
		}
	}

	void regist_loc(int ch, int location){
		locationTable[ch][index[ch]] = location;
		index[ch]++;
	}

	int next_loc(int ch){
		int ret = locationTable[ch][index[ch]];
		index[ch]++;
		return ret;
	}

private:
	int** locationTable;
	int index[128];
};

int main(){

	for(int i = 0; i < 128; i++)T_char_count[i] = 0;

	int length;

	char* T = new char[1000001];
	scanf("%s",T);

	for(length = 0; T[length] != '\0';length++){
		T_char_count[T[length]]++;
	}

	LocRecord locRecord;
	locRecord.init();

	//T[i]????????????i??§???????????¨????¨????
	for(int i = 0; i < length; i++){
		locRecord.regist_loc(T[i],i);
	}

	ull* HASH = new ull[length+1];
	ull* P = new ull[length+1];

	HASH[0] = 0;
	P[0] = 1;

	//T??????????????\???????±???????
	for(int i = 1; i <= length; i++){
		HASH[i] = T[i-1] + HASH[i-1]*MOD;
		P[i] = P[i-1]*MOD;
	}

	int Q,S_length,left,P_char_count[128];
	scanf("%d",&Q);

	char S[1001];
	ull S_HASH[1001],S_value,T_value;
	bool FLG;

	for(int loop = 0; loop < Q; loop++){
		scanf("%s",S);

		for(int i = 0; i < 128; i++){
			P_char_count[i] = 0;
		}

		for(S_length = 0;S[S_length] != '\0';S_length++){
			P_char_count[S[S_length]]++;
		}

		FLG = true;

		for(int i = 0; i < 128; i++){
			if(T_char_count[i] < P_char_count[i]){
				printf("0\n");
				FLG = false;
				break;
			}
		}
		if(!FLG)continue;


		S_HASH[0] = 0;
		for(int i = 1; i <= S_length; i++){
			S_HASH[i] = S[i-1] + S_HASH[i-1]*MOD;
		}

		S_value = S_HASH[S_length];

		locRecord.init_index();

		FLG = false;

		while((left = locRecord.next_loc(S[0])) != -1){
			if(left+S_length-1>=length)break;

			if(T[left+S_length-1] != S[S_length-1])continue;

			T_value = HASH[left+S_length]-HASH[left]*P[S_length];

			if(T_value == S_value){
				FLG = true;
				break;
			}
		}

		if(FLG){
			printf("1\n");
		}else{
			printf("0\n");
		}
	}

	return 0;
}