#include using ll = long long; using uint = unsigned; using namespace std; const int mxn = 2e5 + 10; int TestCase, f[mxn][3]; signed main() { for (scanf("%d", &TestCase); TestCase--;) { int n; scanf("%d", &n); vector a(n); for (int &x : a) scanf("%d", &x); for (int i = 0; i <= n; ++i) memset(f[i], 0, sizeof f[i]); f[0][1] = f[1][a[0] * 2] = 1; for (int i = 2; i <= n; ++i) { if (a[i - 1] == a[i - 2]) for (int k = 0; k < 3; ++k) f[i][k] |= f[i - 1][k]; else f[i][1] |= f[i - 2][1]; if (a[i - 1] == 0) { f[i][0] |= f[i - 1][0] | f[i - 1][1]; f[i][1] |= f[i - 1][2]; } else { f[i][1] |= f[i - 1][0]; f[i][2] |= f[i - 1][2] | f[i - 1][1]; } } puts(f[n][1] ? "Yes" : "No"); } return 0; }