import java.util.Scanner; public class JerryStacks { public static void main( String[] args ) { Scanner sc = new Scanner( System.in ); int numTests = Integer.parseInt( sc.nextLine() ); // reads the number of test cases for( int i = 0; i < numTests; i++ ) { int listSize = Integer.parseInt( sc.nextLine() ); String[] original = new String[listSize]; // initialize original array String[] desired = new String[listSize]; // initialize desired array for( int j = 0; j < listSize; j++ ) { original[j] = sc.nextLine(); } for( int k = 0; k < listSize; k++ ) { desired[k] = sc.nextLine(); } int oc, dc; oc = dc = listSize; // Initialize counters for original and desired stack. int popcounter = 0; while ( oc > 0 ) { if ( original[oc-1].equals( desired[dc-1] ) ) { oc--; dc--; } else { oc--; popcounter++; } } System.out.println(popcounter); for ( int x = (popcounter); x > 0; x--) System.out.println(desired[x-1]); } } }