/*
最长上升子序列
经典的 nlog(n)解法,二分
*/
// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>
using namespace std;
// typedef
typedef __int64 LL;
//
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#define Z(a,b) ((a)<<(b))
#define Y(a,b) ((a)>>(b))
const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 1000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);
template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
if(x>y) return x;
return y;
}
template<class T> inline T TMIN(T x,T y)
{
if(x<y) return x;
return y;
}
template<class T> inline T MMAX(T x,T y,T z)
{
return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
return TMIN(TMIN(x,y),z);
}
template<class T> inline void SWAP(T &x,T &y)
{
T t = x;
x = y;
y = t;
}
// code begin
int T;
int N;
int A[40010];
int stk[40010],top;
int main()
{
read;
write;
int l,r,mid;
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
for(int i=0;i<N;i++)
{
scanf("%d",A+i);
}
top = 0;
stk[top++] = A[0];
for(int i=1;i<N;i++)
{
l = 0;
r = top;
while(l<r)
{
mid = (l+r)/2;
if(A[i]==stk[mid])
{
l = mid;
break;
}
if(A[i]>stk[mid])
{
l = mid+1;
}
else
{
r = mid;
}
}
if(l==top)
stk[top++] = A[i];
else
stk[l] = A[i];
//printf("[%d %d] ",l,top);
}
printf("%d\n",top);
}
return 0;
}