Go: package main

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

func main() {
	io := NewIo()
	defer io.Flush()

	for {
		N := io.NextInt()
		if N == 0 {
			break
		}
		set := make([]map[int]struct{}, N)
		for i := 0; i < N; i++ {
			set[i] = make(map[int]struct{})
			M := io.NextInt()
			for j := 0; j < M; j++ {
				p := io.NextInt()
				set[i][p] = struct{}{}
			}
		}
		K := io.NextInt()
		l := make([]int, K)
		for i := 0; i < K; i++ {
			l[i] = io.NextInt()
		}

		ans := 0
	FOR_OUTER:
		for i := 0; i < N; i++ {
			for j := 0; j < K; j++ {
				if _, f := set[i][l[j]]; f == false {
					continue FOR_OUTER
				}
			}
			switch ans {
			case 0:
				ans = i + 1
			default:
				ans = -1
			}
		}
		if ans > 0 {
			io.Println(ans)
		} else {
			io.Println(-1)
		}
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

Python: import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


SIZE = 105
table = [[False]*SIZE for _ in range(SIZE)]


while True:

    N = int(input())
    if N == 0:
        break

    for i in range(N):
        for k in range(N):
            table[i][k] = False

    for i in range(N):
        input_array = list(map(int,input().split()))
        num = input_array[0]
        for k in range(1,(num+1)):
            table[i][input_array[k]-1] = True

    people = list(map(int,input().split()))
    num = people[0]

    candidate = 0
    ans = -1

    for i in range(N):
        FLG = True
        for k in range(1,num+1):
            if table[i][people[k]-1] == False:
                FLG = False
                break
        if FLG == True:
            candidate += 1
            ans = i

    if candidate != 1:
        print("-1")
    else:
        print("%d"%(ans+1))

Python: while 1:
    n=int(input())
    if not n:break
    l=[]
    for _ in range(n):
        m=set(map(int,input().split()[1:]))
        l.extend([m])
    o=set(map(int,input().split()[1:]))
    cd=[i+1 for (i,j) in enumerate(l) if j&o==o]
    if len(cd)!=1:
        print("-1")
    else:
        print(cd[0])

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N = int(input())
    if N == 0:
        break
    member = [list(map(int,input().split(" ")))[1:] for i in range(0,N)]
    leaked = list(map(int,input().split(" ")))
    leak_list = [0 for i in range(leaked[0])]
    ans = -1
    for i in range(N):
        count = 0
        for m in member[i]:
            if m in leaked[1:]:
                count += 1
        if count == len(leaked[1:]):
            if ans != -1:
                print(-1)
                break
            else:
                ans = i + 1
    else:
        print(ans)

Python: #!/usr/bin/env python3
while True:
    n = int(input())
    if n == 0:
        exit()
    p = [None] * n
    for i in range(n):
        m, *p[i] = map(int, input().split())
    k, *l = map(int, input().split())
    ans = []
    for i in range(n):
        if all(x in p[i] for x in l):
            ans.append(i + 1)
    print(ans[0] if len(ans) == 1 else -1)

Python: import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break
        a = [set(LI()[1:]) for _ in range(n)]
        s = set((LI()[1:]))
        r = -1
        for c,i in zip(a,range(1,n+1)):
            if not (s - c):
                if r != -1:
                    r = -1
                    break
                r = i
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

Python: import sys
from operator import itemgetter

inf = 1<<30

def solve():
    while 1:
        N = int(sys.stdin.readline().rstrip())

        if N == 0:
            return

        p = [set(list(map(int, sys.stdin.readline().split()))[1:]) for i in range(N)]
        l = list(map(int, sys.stdin.readline().split()))[1:]

        cnt = 0
        suspect = -1

        for i, pi in enumerate(p, start=1):
            if all(li in pi for li in l):
                cnt += 1
                suspect = i

                if cnt > 1:
                    print(-1)
                    break
        else:
            if cnt == 1:
                print(suspect)
            else:
                print(-1)


if __name__ == '__main__':
    solve()

Python: while True:
    N = int(input())
    if N == 0:break
    flgs = [0 for i in range(N)]
    for i in range(N):
        src = map(int,input().split())
        for k in src[1:]:
            flgs[i] |= (1 << k)
    target = 0
    src = map(int,input().split())
    for k in src[1:]:
        target |= (1 << k)

    ans = -1
    for i in range(N):
        if (flgs[i] | target) == flgs[i]:
            if ans < 0:
                ans = i+1
            else:
                ans = -1
                break
    print(ans)

Python: while 1:
    n = int(input())
    if n == 0:
        break

    infos = []
    for _ in range(n):
        info = list(map(int, input().split()))
        tmp = info.pop(0)
        infos.append(info)

    target = list(map(int, input().split()))
    tmp = target.pop(0)

    flag = False
    for i, info in enumerate(infos):
        for t in target:
            if t not in info:
                break
        else:
            if flag:
                print(-1)
                break
            else:
                ans = i + 1
                flag = True
    else:
        if flag:
            print(ans)
        else:
            print(-1)