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: import java.io.*;
  import java.util.*;
  import static java.lang.Math.*;
  
  public class D{
  	
  	
  	static int n;
  	static int[] c;
  	
  	static class Build implements Comparable<Build>{
  		int[] a;
  		public Build() {
  			a=new int[n];
  			Arrays.fill(a, -1);
  		}
  		public int  compareTo(Build o) {
  			for (int i= 0; i<n; i++) {
  				if(a[i]==-1  || o.a[i]==-1) return 0;
  				if(a[i]==o.a[i])continue;
  				else  return a[i]-o.a[i];
  			}
  			return  0;
  		}
  	}
  	
  	static long[][] a;
  	
  	static Build ans;
  	
  	static void solve(int cur, Build b, boolean allGood) {
  		if (!q.contains(b)) {
  			allGood = true;
  		}
  		if (cur == n) {
  			if (!q.contains(b)) {
  				long sb = 0, sa = 0;
  				for (int i  = 0; i < n;i++) {
  					sb+=a[i][b.a[i]];
  					sa+=a[i][ans.a[i]];
  				}
  				if (sb>sa) {
  					for (int i = 0;i<n;i++) ans.a[i]  = b.a[i];
  				}
  			}
  			return;
  		}
  		if (allGood) {
  			b.a[cur] = c[cur]-1;
  			solve(cur+1,b,allGood);
  		}
  		else {
  			for (int i=c[cur]-1; i >=0; i--) {
  				b.a[cur] = i;
  				solve(cur+1,b,allGood);
  				if (!q.contains(b)) break;
  			}
  		}
  		b.a[cur] = -1;
  	}
  	
  	
  	static TreeSet<Build> q = new TreeSet<Build>();
  
  	public static void main(String[] args) throws IOException {
  		// br = new BufferedReader(new FileReader(".in"));
  		// out = new PrintWriter(new FileWriter(".out"));
  		//new Thread(null, new (), "peepee", 1<<28).start();
  		
  		n =readInt();
  a = new long[n][];
  c= new  int[n];
  		for (int  i= 0;i < n; i++) {
  			c[i]=readInt();
  			a[i] =new long[c[i]];
  			for(int j=0;j<c[i];j++)a[i][j]=readLong();
  		}
  		// Literally just shitty  greedy  or someth,  generatetop m-1 builds
  		int m  =readInt();
  		while(m-->0) {
  			Build b = new Build();
  			for (int  i  =  0; i<n; i++)b.a[i]=readInt()-1;
  			q.add(b);
  		}
  		Build b  =  new Build();
  		ans  = new Build();
  		for (int i = 0; i<  n; i++)ans.a[i]=0;
  		
  		solve(0, b, false);
  		
  		for (int x: ans.a) System.out.print(x+1 + " ");
  		System.out.println();
  	}
  	
  	/* Stupid things to try if stuck:
  	 * n=1, expand bsearch range
  	 * brute force small patterns
  	 * submit stupid intuition
  	 */
  	
  	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  	static StringTokenizer st = new StringTokenizer("");
  	static String read() throws IOException{return st.hasMoreTokens() ? st.nextToken():(st = new StringTokenizer(br.readLine())).nextToken();}
  	static int readInt() throws IOException{return Integer.parseInt(read());}
  	static long readLong() throws IOException{return Long.parseLong(read());}
  	static double readDouble() throws IOException{return Double.parseDouble(read());}
  }