- import java.util.ArrayList;
- import java.util.Scanner;
- class Main {
- public static void main(String args[]) {
- // encapsulate System.in for better input parsing
- Scanner in = new Scanner(System.in);
- // for each testcase
- int tCases = in.nextInt();
- for (int i = 0; i < tCases; i++) {
- int count = in.nextInt();
- ArrayList<Integer> numbers = new ArrayList<Integer>();
- for (int j = 0; j < count; j++) {
- numbers.add(in.nextInt());
- }
- Table table = new Table(numbers);
- System.out.println(table.calcMax());
- }
- }
- }
- class Item {
- public Item(int i, int j) {
- count = i;
- value = j;
- }
- int count;
- int value;
- }
- class Table {
- int count;
- ArrayList<Integer> numbers;
- ArrayList<Item> maxima;
- public Table(ArrayList<Integer> numbers) {
- count = numbers.size();
- this.numbers = numbers;
- dpTable2 = new int[count];
- maxima = new ArrayList<Item>();
- }
- int[] dpTable2;
- public int calcMax() {
- maxima.add(new Item(1,numbers.get(count-1)));
- for (int i = count - 2; i >= 0; i--) {
- calc(i);
- }
- return maxima.get(0).count;
- }
- private void calc(int pos) {
- int max = 0;
- for (int i = 0; i < maxima.size(); i++) {
- if (maxima.get(i).value > numbers.get(pos)) {
- max = maxima.get(i).count;
- for (int j = i; j >= 0; j--) {
- if (maxima.get(j).count > max) {
- maxima.add(j, new Item(max + 1,numbers.get(pos)));
- return;
- }
- }
- maxima.add(0, new Item(max + 1, numbers.get(pos)));
- return;
- }
- }
- maxima.add(new Item(1, numbers.get(pos)));
- return;
- }
- }