#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i(0); i < (n); ++i) #define rep(i, a, b) for(int i(a); i <= (b); ++i) #define dec(i, a, b) for(int i(a); i >= (b); --i) #define for_edge(i, x) for(int i = H[x]; i; i = X[i]) #define LL long long #define ULL unsigned long long #define MP make_pair #define PB push_back #define FI first #define SE second #define INF 1 << 30 const int N = 100000 + 10; const int M = 10000 + 10; const int Q = 1000 + 10; const int A = 30 + 1; typedef long long ll; int T; int n; ll a[Q]; ll c[Q][Q]; ll mx[Q],s[Q],ans; ll f[Q][Q]; int i,j,k; int dfs(int cur,int tot) { if(!cur){ if(tot>ans) return ans=tot,1; return 0; } for(int i=0,j,u,nxt;i<cur;i++) { if(cur-i+tot<=ans) return 0; u=f[tot][i],nxt=0; if(mx[u]+tot<=ans) return 0; for(int j=i+1;j<cur;j++) if(c[u][f[tot][j]]) f[tot+1][nxt++]=f[tot][j]; if(dfs(nxt,tot+1)) return 1; } return 0; } int main(){ for (scanf("%d", &T); T--; ){ scanf("%d", &n); memset(c, 0, sizeof c); rep(i, 1, n) scanf("%lld", a + i); rep(i, 1, n - 1) rep(j, i + 1, n){ if (a[i] % a[j] != 0 && a[j] % a[i] != 0){ c[i-1][j-1] = c[j-1][i-1] = 1; } } /* rep(i, 1, n){ rep(j, 1, n) printf("%d ", c[i][j]); putchar(10); }*/ memset(mx,0,sizeof(mx)); memset(s,0,sizeof(s)); ans=0; for(i=n-1;~i;dfs(k,1),mx[i--]=ans) for(k=0,j=i+1;j<n;j++) if(c[i][j]) f[1][k++]=j; printf("%lld\n",ans); } return 0; }