description: Ivan is playing yet another roguelike computer game. He controls a single hero in the game. The hero has n equipment slots. There is a list of c_i items for the i-th slot, the j-th of them increases the hero strength by a_{i,j}. The items for each slot are pairwise distinct and are listed in the increasing order of their strength increase. So, a_{i,1} < a_{i,2} < ... < a_{i,c_i}.
  
  For each slot Ivan chooses exactly one item. Let the chosen item for the i-th slot be the b_i-th item in the corresponding list. The sequence of choices [b_1, b_2, ..., b_n] is called a build.
  
  The strength of a build is the sum of the strength increases of the items in it. Some builds are banned from the game. There is a list of m pairwise distinct banned builds. It's guaranteed that there's at least one build that's not banned.
  
  What is the build with the maximum strength that is not banned from the game? If there are multiple builds with maximum strength, print any of them.
  
  Input
  
  The first line contains a single integer n (1 ≤ n ≤ 10) — the number of equipment slots.
  
  The i-th of the next n lines contains the description of the items for the i-th slot. First, one integer c_i (1 ≤ c_i ≤ 2 ⋅ 10^5) — the number of items for the i-th slot. Then c_i integers a_{i,1}, a_{i,2}, ..., a_{i,c_i} (1 ≤ a_{i,1} < a_{i,2} < ... < a_{i,c_i} ≤ 10^8).
  
  The sum of c_i doesn't exceed 2 ⋅ 10^5.
  
  The next line contains a single integer m (0 ≤ m ≤ 10^5) — the number of banned builds.
  
  Each of the next m lines contains a description of a banned build — a sequence of n integers b_1, b_2, ..., b_n (1 ≤ b_i ≤ c_i).
  
  The builds are pairwise distinct, and there's at least one build that's not banned.
  
  Output
  
  Print the build with the maximum strength that is not banned from the game. If there are multiple builds with maximum strength, print any of them.
  
  Examples
  
  Input
  
  
  3
  3 1 2 3
  2 1 5
  3 2 4 6
  2
  3 2 3
  3 2 2
  
  
  Output
  
  
  2 2 3 
  
  
  Input
  
  
  3
  3 1 2 3
  2 1 5
  3 2 4 6
  2
  3 2 3
  2 2 3
  
  
  Output
  
  
  1 2 3
  
  
  Input
  
  
  3
  3 1 2 3
  2 1 5
  3 2 4 6
  2
  3 2 3
  2 2 3
  
  
  Output
  
  
  3 2 2
  
  
  Input
  
  
  4
  1 10
  1 4
  1 7
  1 3
  0
  
  
  Output
  
  
  1 1 1 1 
solution: 							/*
  							ID: abdelra29
  		LANG: JAVA
  		PROG: zerosum
  							*/
  								/*
  								TO LEARN
  						
  								2-euler tour
  							
  								*/
  								/*
  								TO SOLVE 
  								*/
  								/*
  								bit manipulation shit
  								1-Computer Systems: A Programmer's Perspective
  								2-hacker's delight
  								*/
  								/*
  								TO WATCH
  								
  								*/
  								            import java.util.*;
  										    import java.math.*;
  										    import java.io.*; 
  										    import java.text.DecimalFormat;
  										    import java.util.stream.Collectors;
  
  
  										       public class A{
  								            static FastScanner scan=new FastScanner();
  											     public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
  
  				public static void main(String[] args)  throws Exception 
  								      {
  								 /*
  								 very important tips 
  								 1-just fucking think backwards once in your shitty life
  								 2-consider brute forcing and finding some patterns and observations
  								 3-when you're in contest don't get out because you think there is no enough time
  								 4-don't get stuck on one approach 
  								 */
  							   
  				//scan=new FastScanner("evaluations.in");
  				//out = new PrintWriter("sabotage.out");
  
  							
  										 							 /*
  										 READING 
  								
  										 3-Introduction to DP with Bit-masking codeforces
  										 4-Bit Manipulation hacker-earth
  										 5-read more about mobious and inclusion-exclusion 
  					 				     6-read more about Fermat little theorem
  										 */
  										 /*
  										
  										 */
  										 
  
  					 			
  										      
  	int tt=1;
  			//					tt=scan.nextInt();
                                   int T=1;
  
  									 outer:while(tt-->0)
  									    {
  									    	int n=scan.nextInt();
  									    	int sumM=0;
  									    	int cc[]=new int[n];
  									    	ArrayList<Integer>arr[]=new ArrayList[n];
  									    	for(int i=0;i<n;i++)
  									    		arr[i]=new ArrayList();
  									    	ArrayList<Integer>src=new ArrayList<Integer>();
  									    	for(int i=0;i<n;i++)
  									    	{
  									    		cc[i]=scan.nextInt();
  									    		for(int j=0;j<cc[i];j++)
  									    		{
  									    			int k=scan.nextInt();
  									    		  arr[i].add(k);
  									    		}
  									    		src.add(cc[i]-1);
  									    		sumM+=(arr[i].get(arr[i].size()-1));
  									    	}
  									    	//out.println(sumM);
  									    	int m=scan.nextInt();
  									    	Set<Integer>set[]=new HashSet[(int)2e5+4];
  									    	for(int i=0;i<(int)2e5+4;i++)
  									    		set[i]=new HashSet();
  									    	Set<ArrayList<Integer>>has=new HashSet<ArrayList<Integer>>();
  									    	for(int i=0;i<m;i++)
  									    	{
  									    		ArrayList<Integer>now=new ArrayList<Integer>();
  									    		for(int j=0;j<n;j++)
  									    		{
  									    			int x=scan.nextInt();
  									    			now.add(x-1);
  									    			set[x-1].add(j);
  									    		}
  									    		has.add(now);
  									    	}
  									    //	out.println(sumM);
  									    	PriorityQueue<special>pq=new PriorityQueue<special>();
  									        pq.add(new special(sumM,src));
  									   //  out.println(pq.peek().sum);
  									        Set<ArrayList<Integer>>vis=new HashSet<ArrayList<Integer>>();
  									        while(!pq.isEmpty())
  									        {
  									        	special sp=pq.poll();
  									        	//out.println("F "+sp.sum+" "+sp.arr);
  									        	ArrayList<Integer>asp=sp.arr;
  									        	if(vis.contains(asp))
  									        		continue;
  									        	vis.add(asp);
  									        	if(!has.contains(asp)){
  									        	//	out.println(sp.sum);
  									        		for(int i=0;i<n;i++)
  									        			out.print((asp.get(i)+1)+" ");
  									        		out.close();
  									        		return;
  									        	}
  									        	for(int i=0;i<n;i++)
  									        	{
  									        		ArrayList<Integer>cur=new ArrayList<Integer>(asp);
  									        		if(cur.get(i)-1>=0)
  									        		{
  									        			cur.set(i,cur.get(i)-1);
  									        			int cursum=sp.sum-arr[i].get(cur.get(i)+1)+arr[i].get(cur.get(i));
  									        				pq.add(new special(cursum,cur));
  									        			}
  									        		}
  									        	}
  									        
  
  									   
  
  									    
  
  		 }							
  		
  	        
  
  				out.close();
  							}
  							
  							
  
  							static class special implements Comparable<special>{
  							int sum;
  							ArrayList<Integer>arr;
  							public special(int sum,ArrayList<Integer>arr)
  							{
  								this.sum=sum;
  								this.arr=new ArrayList<Integer>(arr);
  							}
  
  								
  										            public int compareTo(special o1)
  										            {
  										            	return o1.sum-sum;
  										            }
  							}
  				
  										   
  										     static long binexp(long a,long n)
  										    {
  										        if(n==0)
  										            return 1;
  										        long res=binexp(a,n/2);
  										        if(n%2==1)
  										            return res*res*a;
  										        else 
  										            return res*res;
  										    }
  										     
  										    static long powMod(long base, long exp, long mod) {
  										           if (base == 0 || base == 1) return base;
  										           if (exp == 0) return 1;
  										           if (exp == 1) return (base % mod+mod)%mod;
  										           long R = (powMod(base, exp/2, mod) % mod+mod)%mod;
  										           R *= R;
  										           R %= mod;
  										           if ((exp & 1) == 1) {
  										               return (base * R % mod+mod)%mod;
  										           }
  										           else return (R %mod+mod)%mod;
  										       }
  										    static double dis(double x1,double y1,double x2,double y2)
  										    {
  										        return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  										    }
  										    static long mod(long x,long y)
  										        {
  										            if(x<0)
  										                x=x+(-x/y+1)*y;
  										            return x%y;
  										        }
  										     public static  long pow(long b, long e) {
  										                long r = 1;
  										                while (e > 0) {
  										                    if (e % 2 == 1) r = r * b ;
  										                    b = b * b;
  										                    e >>= 1;
  										                }
  										                return r;
  										            }
  										    private static void sort(int[] arr) {
  										            List<Integer> list = new ArrayList<>();
  										            for (int object : arr) list.add(object);
  										            Collections.sort(list);
  										        //Collections.reverse(list);
  										            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
  										        }
  										    private static void sort2(long[] arr) {
  										            List<Long> list = new ArrayList<>();
  										            for (Long object : arr) list.add(object);
  										            Collections.sort(list);
  										        Collections.reverse(list);
  										            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
  										        }
  										     static class FastScanner
  								{
  								    private int BS = 1 << 16;
  								    private char NC = (char) 0;
  								    private byte[] buf = new byte[BS];
  								    private int bId = 0, size = 0;
  								    private char c = NC;
  								    private double cnt = 1;
  								    private BufferedInputStream in;
  								 
  								    public FastScanner() {
  								        in = new BufferedInputStream(System.in, BS);
  								    }
  								 
  								    public FastScanner(String s) {
  								        try {
  								            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
  								        } catch (Exception e) {
  								            in = new BufferedInputStream(System.in, BS);
  								        }
  								    }
  								 
  								    private char getChar() {
  								        while (bId == size) {
  								            try {
  								                size = in.read(buf);
  								            } catch (Exception e) {
  								                return NC;
  								            }
  								            if (size == -1) return NC;
  								            bId = 0;
  								        }
  								        return (char) buf[bId++];
  								    }
  								 
  								    public int nextInt() {
  								        return (int) nextLong();
  								    }
  								 
  								    public int[] nextInts(int N) {
  								        int[] res = new int[N];
  								        for (int i = 0; i < N; i++) {
  								            res[i] = (int) nextLong();
  								        }
  								        return res;
  								    }
  								 
  								    public long[] nextLongs(int N) {
  								        long[] res = new long[N];
  								        for (int i = 0; i < N; i++) {
  								            res[i] = nextLong();
  								        }
  								        return res;
  								    }
  								 
  								    public long nextLong() {
  								        cnt = 1;
  								        boolean neg = false;
  								        if (c == NC) c = getChar();
  								        for (; (c < '0' || c > '9'); c = getChar()) {
  								            if (c == '-') neg = true;
  								        }
  								        long res = 0;
  								        for (; c >= '0' && c <= '9'; c = getChar()) {
  								            res = (res << 3) + (res << 1) + c - '0';
  								            cnt *= 10;
  								        }
  								        return neg ? -res : res;
  								    }
  								 
  								    public double nextDouble() {
  								        double cur = nextLong();
  								        return c != '.' ? cur : cur + nextLong() / cnt;
  								    }
  								 
  								    public double[] nextDoubles(int N) {
  								        double[] res = new double[N];
  								        for (int i = 0; i < N; i++) {
  								            res[i] = nextDouble();
  								        }
  								        return res;
  								    }
  								 
  								    public String next() {
  								        StringBuilder res = new StringBuilder();
  								        while (c <= 32) c = getChar();
  								        while (c > 32) {
  								            res.append(c);
  								            c = getChar();
  								        }
  								        return res.toString();
  								    }
  								 
  								    public String nextLine() {
  								        StringBuilder res = new StringBuilder();
  								        while (c <= 32) c = getChar();
  								        while (c != '\n') {
  								            res.append(c);
  								            c = getChar();
  								        }
  								        return res.toString();
  								    }
  								 
  								    public boolean hasNext() {
  								        if (c > 32) return true;
  								        while (true) {
  								            c = getChar();
  								            if (c == NC) return false;
  								            else if (c > 32) return true;
  								        }
  								    }
  								}
  
  										     static class Pair implements Comparable<Pair>{
  										            public long x, y,z;
  										            public Pair(long x1, long y1,long z1) {
  										                x=x1;
  										                y=y1;
  										                z=z1;
  										            }
  										             public Pair(long x1, long y1) {
  										                x=x1;
  										                y=y1;
  										    
  										            }
  										            
  										            @Override
  										            public int hashCode() {
  										                return (int)(x + 31 * y);
  										            }
  										            public String toString() {
  										                return x + " " + y+" "+z;
  										            }
  										            @Override
  										            public boolean equals(Object o){
  										                if (o == this) return true;
  										                if (o.getClass() != getClass()) return false;
  										                Pair t = (Pair)o;
  										                return t.x == x && t.y == y&&t.z==z;
  										            }
  										    public int compareTo(Pair o)
  										    {
  										    								  	
  										  
  										  	return (int)(y-o.y);
  
  										    	
  										     
  										        }
  										     
  										    }
  										}
  										
  										    
  										   
  
  										     
  