import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.regex, std.conv, std.stdio, std.typecons; void main() { auto t = readln.chomp.to!size_t; foreach (_; 0..t) { auto n = readln.chomp.to!size_t; auto ai = readln.split.map!(to!int).array; writeln(calc(n, ai)); } } int calc(size_t n, int[] ai) { auto memo = new int[][](n, n); int dp(size_t i1, size_t i2 = size_t.max) { auto maxR = 1; if (i2 == size_t.max) { foreach (j; i1+1..n) maxR = max(maxR, dp(j, i1) + 1); } else { if (memo[i1][i2] > 0) { maxR = memo[i1][i2]; } else { auto d = ai[i1] - ai[i2]; if (d > 0) { foreach (j; i1+1..n) if (ai[j] - ai[i1] > d || ai[j] - ai[i1] < 0) maxR = max(maxR, dp(j, i1) + 1); } else { foreach (j; i1+1..n) if (ai[j] - ai[i1] > d && ai[j] - ai[i1] < 0) maxR = max(maxR, dp(j, i1) + 1); } memo[i1][i2] = maxR; } } return maxR; } auto maxR = 0; foreach (i; 0..n) maxR = max(maxR, dp(i)); return maxR; }