////////////////////////////////////
// Maximum ascending order
// Use the DP + binary method
// If the conventional method is used, the time of N ^ 2 is used, and the time after the second is used is reduced to nlogn.
// This kind of bipartite method is clever. First get an array st [], read a [I] each time, and find the last st [k] That is smaller than it in St [].
// Replace s [k] with a [I]. When K is smaller than Len, this replacement will not change the maximum number of the longest chain; when K is Len, the maximum number of chains
// It is changed to a smaller number A [I], which does not affect the extension of the chain and is easier to lengthen. When k = Len + 1, simply lengthen one a [I]
// However, this method cannot output the oldest sequence.
# Include <iostream>
Using namespace STD;
Unsigned int A [40005];
Unsigned int st [40005];
Int main ()
{
Unsigned int I, n, num, Len, left, right, mid;
Cin> N;
While (n --)
{
Cin> num;
For (I = 0; I <num; I ++)
Cin> A [I];
St [0] = 0;
St [1] = A [0];
Len = 1;
For (I = 1; I <num; I ++)
{
Left = 0; Right = Len;
While (left <= right)
{
Mid = (left + right)/2;
If (ST [Mid] <= A [I])
Left = Mid + 1; // set left to the next K smaller than a [I]
Else
Right = mid-1;
}
St [left] = A [I];
If (left> Len)
Len ++;
}
Cout <Len <Endl;
}
Return 0;
}