<?php  
$target = trim(fgets(STDIN));
$q = trim(fgets(STDIN));

for ($i=0; $i < $q; $i++){ 
	$pattern = trim(fgets(STDIN));
	if(preg_match("/$pattern/", $target)){
		echo "1\n";
	}else{
		echo "0\n";
	}
}

?>
