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)
}

C++: #include <stdio.h>
#include <string.h>

int main(void){
	int member[100][100], leak, n, m, i, j, x, count, res, flag;
	scanf("%d",&n);
	while(n){
		memset(member,0,sizeof(member));
		for(i = 0;i < n;i++){
			scanf("%d",&m);
			for(j = 0;j < m;j++){
				scanf("%d",&x);
				member[i][x - 1] = 1;
			}
		}
		scanf("%d",&m);
		res = -1;
		flag = 0;
		for(i = 0;i < m && res == -1;i++){
			scanf("%d",&leak);
			count = 0;
			for(j = 0;j < n;j++)
				if(member[j][leak - 1]) count++;
			if(!flag && count == 1){
				for(j = 0;j < n;j++)
					if(member[j][leak - 1]) break;
				res = j + 1;
				flag = 1;
			}else if(flag && count == 1)
				res = -1;
		}
		printf("%d\n",res);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}

int a[1000][1000];
int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    int b,d;
    lp(i,n){
      cin>>b;
      lp(j,b){
	cin>>d;
	a[i][d]=1;
      }
    }
    int count=0,ans,check;
    int c;
    cin>>c;
    int x[1000];
    lpin(x,i,c);
    lp(i,n){
      check=0;
      lp(j,c){
	if(a[i][x[j]]==1) 1;
	else check=1;
      }
      if(check==0){
	ans=i;
	count++;
      }
    }
    if(count==1) cout<<ans+1<<endl;
    else cout<<"-1"<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int n;
	
	while (cin >> n, n) {
		bool f[101][101] = {false};
		rep(i, n) {
			int m = in();
			rep(j, m) {
				f[i][in()] = true;
			}
		}

		vi a, l;
		
		int k = in();
		rep(i, k) l.pb(in());

		rep(i, n) {
			bool beet = true;
			rep(j, l.size()) {
				if (!f[i][l[j]]) beet = false;
			}
			if (beet) a.pb(i + 1);
		}

		cout << (a.size() == 1 ? a[0] : -1) << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <cmath>
#include <fstream>
#include <random>
#include <iostream>
#include <algorithm>

using namespace std;


int main(){
  int n, m, k;
  bool flag, all_flag;
  vector< vector<int> > v;
  vector<int> leakage;
  vector<int> answer;
  vector<int> ms;
  while(true){
    cin >> n;
    if (n == 0)
    {
      break;
    }
    v.reserve(n);
    for (int i = 0; i < n; ++i)
    {
      cin >> m;
      ms.push_back(m);
      v[i].reserve(m);
      for (int j = 0; j < m; ++j)
      {
        cin >> v[i][j];
      }
    }
    cin >> k;
    leakage.reserve(k);
    for (int i = 0; i < k; ++i)
    {
      cin >> leakage[i];
    }

    // cout << n << endl;
    for (int i = 0; i < n; ++i)
    {
      all_flag = true;
      for (int t = 0; t < k; ++t)
      {
        flag = false;
        for (int j = 0; j < ms[i]; ++j)
        {
          if (v[i][j] == leakage[t])
          {
            flag = true;
            break;
          }
        }
        if (flag == false){
          all_flag = false;
          break;
        }
      }
      if (all_flag == true)
      {
        answer.push_back(i+1);
      }
    }
    if (answer.size() == 1){
      cout << answer[0] << endl;
    }else{
      cout << -1 << endl;
    }
    v.clear();
    leakage.clear();
    answer.clear();
    ms.clear();
  }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<vector<int>> t(n);
    REP(i,n){
      int m;
      cin>>m;
      REP(j,m){
        int p;
        cin>>p;
        t[i].push_back(p);
      }
      sort(begin(t[i]),end(t[i]));
    }
    int k;
    cin>>k;
    vector<int> l(k);
    REP(i,k)cin>>l[i];
    vector<int> valid;
    REP(i,n){
      bool f=true;
      REP(j,k){
        if(!binary_search(begin(t[i]),end(t[i]),l[j]))
          f=false;
      }
      if(f)
        valid.push_back(i);
    }
    if(valid.size() == 1)
      cout << valid.front()+1 << endl;
    else
      cout << -1 <<endl;
  }
  return 0;
}