#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]; pair getsum(pair& p1, pair& p2) { int a = p1.first * p2.second + p1.second * p2.first; int b = p1.second * p2.second * 2; int g = gcd(a, b); a /= g, b /= g; return { a,b }; } void init() { int n, o; while (cin >> n >> o) { vector> vp; for (int i = 0; i < n; i++) { vp.emplace_back(o, 1); o ^= 1; } queue< vector> > q; map< vector>, int > mc; q.push(vp); mc[vp] = 1; while (!q.empty()) { auto v = q.front(); q.pop(); if (v.size() == 1) for (int i = 0; i < v.size(); i++) printf("%d/%d%c", v[i].first, v[i].second, " \n"[i + 1 == v.size()]); for (int i = 0; i + 1 < v.size(); i++) { vector> v0; for (int j = 0; j < v.size(); j++) { if (j != i) v0.push_back(v[j]); else v0.push_back(getsum(v[j], v[j + 1])), j++; } if (mc.count(v0)) continue; mc[v0] = 1; q.push(v0); } } } } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); init(); 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 || v.size() >= 9) { puts("Yes"); } else puts("No"); } return 0; }