package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	txt := readLine()
	n, _ := strconv.Atoi(readLine())
	patterns := make([]string, 0)
	for i := 0 ; i < n; i++ {
		tmp := readLine()
		patterns = append(patterns, tmp)
	}
	// fmt.Println(matches)
	for i := range patterns {
		if strings.Contains(txt, patterns[i]) {
			fmt.Println(1)
		} else {
			fmt.Println(0)
		}
	}
}


