#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
unordered_map<int, int> freq;
int max_freq = 0;
for (int &x : a) {
cin >> x;
freq[x]++;
max_freq = max(max_freq, freq[x]);
}
if (n == 2) {
cout << "NO\n";
continue;
}
bool found = false;
for (auto &p : freq) {
if (p.second >= 2) {
int median_candidate = p.first;
int L = 0, E = p.second, G = 0;
for (auto &q : freq) {
if (q.first < median_candidate)
L += q.second;
else if (q.first > median_candidate)
G += q.second;
}
if (n >= 4) {
found = true;
break;
} else if (n == 3) {
if (L == 0 && G >= 1) {
// Sample Input 2: YES
found = true;
break;
} else if (G == 0 && L >= 1) {
// User's Counterexample: NO
found = false;
break;
} else if (L >= 1 && G >= 1) {
found = true;
break;
}
}
}
}
cout << (found ? "YES\n" : "NO\n");
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dW5vcmRlcmVkX21hcD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKG51bGxwdHIpOwoKICAgIGludCB0OwogICAgY2luID4+IHQ7CiAgICB3aGlsZSAodC0tKSB7CiAgICAgICAgaW50IG47CiAgICAgICAgY2luID4+IG47CiAgICAgICAgdmVjdG9yPGludD4gYShuKTsKICAgICAgICB1bm9yZGVyZWRfbWFwPGludCwgaW50PiBmcmVxOwogICAgICAgIGludCBtYXhfZnJlcSA9IDA7CiAgICAgICAgZm9yIChpbnQgJnggOiBhKSB7CiAgICAgICAgICAgIGNpbiA+PiB4OwogICAgICAgICAgICBmcmVxW3hdKys7CiAgICAgICAgICAgIG1heF9mcmVxID0gbWF4KG1heF9mcmVxLCBmcmVxW3hdKTsKICAgICAgICB9CgogICAgICAgIGlmIChuID09IDIpIHsKICAgICAgICAgICAgY291dCA8PCAiTk9cbiI7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KCiAgICAgICAgYm9vbCBmb3VuZCA9IGZhbHNlOwoKICAgICAgICBmb3IgKGF1dG8gJnAgOiBmcmVxKSB7CiAgICAgICAgICAgIGlmIChwLnNlY29uZCA+PSAyKSB7CiAgICAgICAgICAgICAgICBpbnQgbWVkaWFuX2NhbmRpZGF0ZSA9IHAuZmlyc3Q7CiAgICAgICAgICAgICAgICBpbnQgTCA9IDAsIEUgPSBwLnNlY29uZCwgRyA9IDA7CgogICAgICAgICAgICAgICAgZm9yIChhdXRvICZxIDogZnJlcSkgewogICAgICAgICAgICAgICAgICAgIGlmIChxLmZpcnN0IDwgbWVkaWFuX2NhbmRpZGF0ZSkKICAgICAgICAgICAgICAgICAgICAgICAgTCArPSBxLnNlY29uZDsKICAgICAgICAgICAgICAgICAgICBlbHNlIGlmIChxLmZpcnN0ID4gbWVkaWFuX2NhbmRpZGF0ZSkKICAgICAgICAgICAgICAgICAgICAgICAgRyArPSBxLnNlY29uZDsKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICBpZiAobiA+PSA0KSB7CiAgICAgICAgICAgICAgICAgICAgZm91bmQgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChuID09IDMpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoTCA9PSAwICYmIEcgPj0gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAvLyBTYW1wbGUgSW5wdXQgMjogWUVTCiAgICAgICAgICAgICAgICAgICAgICAgIGZvdW5kID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChHID09IDAgJiYgTCA+PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFVzZXIncyBDb3VudGVyZXhhbXBsZTogTk8KICAgICAgICAgICAgICAgICAgICAgICAgZm91bmQgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChMID49IDEgJiYgRyA+PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvdW5kID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBjb3V0IDw8IChmb3VuZCA/ICJZRVNcbiIgOiAiTk9cbiIpOwogICAgfQogICAgcmV0dXJuIDA7Cn0K