#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef unsigned long long ULL; #define MEM(a,b) memset((a),(b),sizeof(a)) const LL INF = 1e9 + 7; const int N = 2e5 + 10; pair vp[N]; int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int ncase; scanf("%d", &ncase); while (ncase--) { int n; scanf("%d", &n); vector v(n); for (auto& x : v) scanf("%d", &x); if (v[0] != v[n - 1]) { puts("Yes"); continue; } while (v.size() >= 2 && v[v.size() - 1] == v[v.size() - 2]) v.pop_back(); reverse(v.begin(), v.end()); while (v.size() >= 2 && v[v.size() - 1] == v[v.size() - 2]) v.pop_back(); int flag = 0; for (int i = 1; i < v.size(); i++) { if (v[i] == v[i - 1]) flag = 1; } if (flag) { puts("Yes"); } else puts("No"); } return 0; }