#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll T,n,a[110];
ll dp[110][110][110];
ll solve(ll ind,ll x,ll y)
{
if(ind == n + 1) return 0;
if(dp[ind][x][y] != -1) return dp[ind][x][y];
ll ret = solve(ind+1,x,y);
if(x == 0) ret = max(ret,1 + solve(ind+1,ind,y)); // chose the 1st element belonging to the increasing seq.
if(y == 0) ret = max(ret,1 + solve(ind+1,x,ind)); // chose the 1st element belonging to the decreasing seq.
if(a[ind] > a[x]) ret = max(ret,1 + solve(ind+1,ind,y));
if(a[ind] < a[y]) ret = max(ret,1 + solve(ind+1,x,ind));
return dp[ind][x][y] = ret;
}
int main()
{
cin >> T;
while(T--)
{
memset(dp,-1,sizeof dp);
cin >> n;
for(ll i=1;i<=n;i++) cin >> a[i];
cout << solve(1,0,0) << endl; // here solve(i , j , k) means we are at the ith index
// 'j' means the last index we had chosen that was part of the INCREASING sequence
// 'k' means the last index we had chosen that was part of the DECREASING sequence
// j >= 0 and k >= 0 , but j == 0 means we have not yet chosen the first increasing sequence number
// likewise k == 0 means the same
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnR5cGVkZWYgbG9uZyBsb25nIGxsOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwpsbCBULG4sYVsxMTBdOwpsbCBkcFsxMTBdWzExMF1bMTEwXTsKbGwgc29sdmUobGwgaW5kLGxsIHgsbGwgeSkKewogICAgaWYoaW5kID09IG4gKyAxKSByZXR1cm4gMDsKICAgIGlmKGRwW2luZF1beF1beV0gIT0gLTEpIHJldHVybiBkcFtpbmRdW3hdW3ldOwogICAgbGwgcmV0ID0gc29sdmUoaW5kKzEseCx5KTsKICAgIGlmKHggPT0gMCkgcmV0ID0gbWF4KHJldCwxICsgc29sdmUoaW5kKzEsaW5kLHkpKTsgICAgIC8vIGNob3NlIHRoZSAxc3QgZWxlbWVudCAgYmVsb25naW5nIHRvIHRoZSBpbmNyZWFzaW5nIHNlcS4KICAgIGlmKHkgPT0gMCkgcmV0ID0gbWF4KHJldCwxICsgc29sdmUoaW5kKzEseCxpbmQpKTsgICAgIC8vIGNob3NlIHRoZSAxc3QgZWxlbWVudCAgYmVsb25naW5nIHRvIHRoZSBkZWNyZWFzaW5nIHNlcS4KICAgIGlmKGFbaW5kXSA+IGFbeF0pIHJldCA9IG1heChyZXQsMSArIHNvbHZlKGluZCsxLGluZCx5KSk7CiAgICBpZihhW2luZF0gPCBhW3ldKSByZXQgPSBtYXgocmV0LDEgKyBzb2x2ZShpbmQrMSx4LGluZCkpOwogICAgcmV0dXJuIGRwW2luZF1beF1beV0gPSByZXQ7Cgp9CmludCBtYWluKCkKewogICAgY2luID4+IFQ7CiAgICB3aGlsZShULS0pCiAgICB7CiAgICAgICAgbWVtc2V0KGRwLC0xLHNpemVvZiBkcCk7CiAgICAgICAgY2luID4+IG47CiAgICAgICAgZm9yKGxsIGk9MTtpPD1uO2krKykgY2luID4+IGFbaV07CiAgICAgICAgY291dCA8PCBzb2x2ZSgxLDAsMCkgPDwgZW5kbDsgLy8gaGVyZSBzb2x2ZShpICwgaiAsIGspIG1lYW5zIHdlIGFyZSBhdCB0aGUgaXRoIGluZGV4CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyAnaicgbWVhbnMgdGhlIGxhc3QgaW5kZXggd2UgaGFkIGNob3NlbiB0aGF0IHdhcyBwYXJ0IG9mIHRoZSBJTkNSRUFTSU5HIHNlcXVlbmNlCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyAnaycgbWVhbnMgdGhlIGxhc3QgaW5kZXggd2UgaGFkIGNob3NlbiB0aGF0IHdhcyBwYXJ0IG9mIHRoZSBERUNSRUFTSU5HIHNlcXVlbmNlCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBqID49IDAgYW5kIGsgPj0gMCAsIGJ1dCBqID09IDAgbWVhbnMgd2UgaGF2ZSBub3QgeWV0IGNob3NlbiB0aGUgZmlyc3QgaW5jcmVhc2luZyBzZXF1ZW5jZSBudW1iZXIKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIGxpa2V3aXNlIGsgPT0gMCBtZWFucyB0aGUgc2FtZQogICAgfQogICAgcmV0dXJuIDA7Cn0K