import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		while (n >= 2 && a.front == a.back)
		{
			n -= 2;
			a = a[1..$ - 1];
		}
		bool ok = false;
		ok |= a.equal (a.retro);
		if (!a.empty)
		{
			auto u = a.filter !(c => c != a.front).array;
			ok |= u.equal (u.retro);
			auto v = a.filter !(c => c != a.back).array;
			ok |= v.equal (v.retro);
	        }
		writeln (ok ? "YES" : "NO");
	}
}
