package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"math/bits"
	"os"
	"strconv"
	"strings"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}

func NewConsole() Console {
	return Console{bufio.NewWriter(os.Stdout)}
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

func PrintList(list []int) {
	con := NewConsole()
	defer con.Flush()
	for i := range list {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}

func Test(b uint64, n uint) int {
	return int(b >> n & 1)
}
func Set(b *uint64, n uint64) {
	(*b) = (*b) | n
}
func Clear(b *uint64, n uint64) {
	(*b) = (*b) & ^n
}
func Flip(b *uint64, n uint64) {
	(*b) = (*b) ^ n
}
func All(b *uint64, mask uint64) int {
	flaged := bits.OnesCount64(mask)
	masked := (*b) & mask
	if flaged == bits.OnesCount64(masked) {
		return 1
	} else {
		return 0
	}
}
func Any(b *uint64, mask uint64) int {
	masked := (*b) & mask
	if 0 < bits.OnesCount64(masked) {
		return 1
	} else {
		return 0
	}
}
func None(b *uint64, mask uint64) int {
	masked := (*b) & mask
	if 0 == bits.OnesCount64(masked) {
		return 1
	} else {
		return 0
	}
}

func Count(b *uint64, mask uint64) int {
	masked := (*b) & mask
	return bits.OnesCount64(masked)
}

func main() {
	con := NewConsole()
	defer con.Flush()

	var q int
	masks := make([]uint64, 0)
	fmt.Scanf("%d", &q)
	lines, _ := ReadLongLines(q)
	for i := range lines {
		args := strings.Split(lines[i], " ")
		n, _ := strconv.Atoi(args[0])
		mask := uint64(0)
		for j := 0; j < n; j++ {
			m, _ := strconv.ParseUint(args[j+1], 10, 64)
			mask += 1 << m
		}
		masks = append(masks, mask)
	}

	var b uint64 = 0
	fmt.Scanf("%d", &q)
	lines, _ = ReadLongLines(q)
	for i := range lines {
		args := strings.Split(lines[i], " ")
		command, _ := strconv.Atoi(args[0])
		switch command {
		case 0:
			n, _ := strconv.ParseUint(args[1], 10, 64)
			con.Printf("%d\n", Test(b, uint(n)))
		case 1:
			n, _ := strconv.Atoi(args[1])
			Set(&b, masks[n])
		case 2:
			n, _ := strconv.Atoi(args[1])
			Clear(&b, masks[n])
		case 3:
			n, _ := strconv.Atoi(args[1])
			Flip(&b, masks[n])
		case 4:
			n, _ := strconv.Atoi(args[1])
			con.Printf("%d\n", All(&b, masks[n]))
		case 5:
			n, _ := strconv.Atoi(args[1])
			con.Printf("%d\n", Any(&b, masks[n]))
		case 6:
			n, _ := strconv.Atoi(args[1])
			con.Printf("%d\n", None(&b, masks[n]))
		case 7:
			n, _ := strconv.Atoi(args[1])
			con.Printf("%d\n", Count(&b, masks[n]))
		case 8:
			n, _ := strconv.Atoi(args[1])
			con.Printf("%d\n", b&masks[n])
		}
	}

}



Measured memory_bytes: 10224