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: while True:
  n = int(raw_input())
  if n == 0:
    break

  data = []

  for i in range(n):
    elements = list(map(int, raw_input().split(' ')))
    uid = elements[0]
    uid = i+1
    ps = elements[1:]
    ps = list(set(ps))
    ps = sorted(ps)

    data.append((uid, ps))

  elements = list(map(int, raw_input().split(' ')))
  query = elements[1:]
  query = list(set(query))
  query = sorted(query)

  ans = []

  for uid, ps in data:
    plausible = True

    for q in query:
      if q not in ps:
        plausible = False

    if plausible:
      ans.append(uid)

  if len(ans) == 1:
    print(ans[0])

  else:
    print(-1)

Python: while True:
    n=int(input())
    if n==0:break
    mem=[]
    crime=-1
    for _ in range(n):
        mem.append(set([int(i) for i in input().split()][1:]))
    o=set([int(i) for i in input().split()][1:])
    for e,i in enumerate(mem):
        if o.intersection(i)==o:
            if crime==-1:crime=e+1
            else:
                crime=-1
                break
    print(crime)

Python: while True:
  n = int(input())
  if n == 0:break
  x = []
  for _ in range(n):
    lst = set(list(map(int, input().split()))[1:])
    x.append(lst)
  
  y = set(list(map(int, input().split()))[1:])
  
  ans = []
  for i, v in enumerate(x,start=1):
    if y - v == set():
      ans.append(i)
  
  if len(ans) == 1:
    print(ans[0])
  else:
    print(-1)

Python: # coding: utf-8
while 1:
    n=int(input())
    if n==0:
        break
    data=[]
    for i in range(n):
        data.append(set(list(map(int,input().split()))[1:]))
    check=set(list(map(int,input().split()))[1:])
    ans=[]
    for i in range(n):
        if check-data[i]==set():
            ans.append(i+1)
    if len(ans)==0 or len(ans)>1:
        print(-1)
    else:
        print(ans[0])

Python: while True:
    N=input()
    if N==0:break
    L=[set(map(int,raw_input().split())[1:]) for i in range(N)]
    K=set(map(int,raw_input().split())[1:])
    ans=[i+1 for i in range(N) if K.issubset(L[i])]
    print -1 if len(ans)!=1 else ans[0]

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

    data = list()
    for i in range(n):
        li = list(map(int, input().split()))
        data.append(set(li[1:]))
    
    flow = list(map(int, input().split()))
    flow = set(flow[1:])
    ans = list()
    for idx, li in enumerate(data):
        if flow.issubset(li):
            ans.append(idx + 1)

    if len(ans) == 1:
        print(ans[0])
    else:
        print(-1)

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

    p = []
    for i in range(n):
        lst = list(map(int, input().split()))[1:]
        p.append(lst)

    l = list(map(int, input().split()))[1:]

    ans = 0
    id = -1
    for i in range(n):
        sum = 0
        for j in l:
            if p[i].count(j):
                sum += 1
        
        if sum == len(l):
            ans += 1
            id = i + 1
    
    if ans == 1:
        print(id)
    else:
        print(-1)

Python: while True:
    N = int(input())
    if N == 0:
        quit()
    k = []
    for i in range(N):
        temp = [int(i) for i in input().split()]
        if temp[0] != 0:
            k.append(temp[1:])
        else:
            k.append([])
    o = [int(i) for i in input().split()][1:]
    ans = []
    for i in range(N):
        if all(j in k[i] for j in o):
            ans.append(i)
    if len(ans) != 1:
        print(-1)
    else:
        print(ans[0]+1)

Python: def solve(A, K):
    flag = False
    duplicate = False
    ret = -1
    for k, v in A.items():
        if set(K) & set(v) == set(K):
            if flag:
                duplicate = True
            else:
                flag = True
                ret = k
    if duplicate:
        return -1
    else:
        return ret


while True:
    N = int(input())
    if N == 0:
        break
    A = {i: [] for i in range(1, N + 1)}
    for i in range(N):
        M = list(map(int, input().split()))
        A[i + 1] = M[1:]
    K = list(map(int, input().split()))
    K = K[1:]
    print(solve(A, K))

Python: while True:
    n = int(input())
    if n == 0:
        break
    arr = [[] for i in range(n)]
    for i in range(n):
        arr[i] = list(map(int, input().split()))[1:]
    k = list(map(int, input().split()))[1:]
    res = -1
    for num, i in enumerate(arr):
        ge = True
        for e in k:
            if e not in i:
                ge = False
                break
        if ge:
            if res >= 0:
                res = -1
                break
            else:
                res = num + 1

    print(res)

Python: 
while True:
	n = int(input())
	if n == 0:
		break
	m = []
	for i in range(n):
		m.append(set(list(map(int, input().split()))[1:]))
	k = set(list(map(int, input().split()))[1:])
	c = 0
	f = [i+1 for i in range(n) if k <= m[i]]
	if len(f) == 1:
		print(f[0])
	else:
		print(-1)