1. 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 497 Strategic Defense Initiative
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=438&mosmsg=Submission+received+with+ID+8069729
*
* @author Barny Porcio
* @version 1.0, 07/01/2010
*
* Method : LIS
* Status : Accepted
* Runtime: 0.392
*/

public class StrategicDefenseInitiative497 {


public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


int testcases = Integer.parseInt(br.readLine());
br.readLine();
boolean first = true;
for(int c = 0; c < testcases; ++c){
LinkedList<Integer> ll = new LinkedList<Integer>();
while(true){
String s = br.readLine();
if(s == null || s.isEmpty()) {
break;
}
ll.add(Integer.parseInt(s));
}

int[] lastneighbor = new int[ll.size()];
int biggest = 0;
int[] longest = new int[ll.size()];
longest[0] = 1;
lastneighbor[0] = -1;
for (int i = 1; i < ll.size(); ++i){
int momentanerwert = ll.get(i);
int vergleich= i;
for (int i2 = i-1; i2 >=0; --i2){
if (ll.get(i2) < momentanerwert && longest[i2] > longest[vergleich] ){
vergleich = i2;
}

}

longest[i] = longest[vergleich]+1;
if (longest[i] == 1)
lastneighbor[i] = -1;
else
lastneighbor[i] = vergleich;
//lla[i] = (LinkedList<Integer>) lla[vergleich].clone();
//System.out.println(ll.get(i));
if (longest[i] > longest[biggest])
biggest = i;
}
LinkedList<Integer> lla = new LinkedList<Integer>();
int a = biggest;
while(a != -1){
lla.addFirst(a);
a = lastneighbor[a];
}
if (first)
first = false;
else
System.out.println();
System.out.println("Max hits: "+lla.size());
for (int i : lla){
System.out.println(ll.get(i));
}
}
}

}