#include <bits/stdc++.h>
using namespace std;
#define ff(i , a , b) for(int i = a; i <= int(b); i++)
#define REP(i, a , b) for(int i = a; i >= int(b); i--)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int ,int> pi;
const ll MAXN = 1e6 + 7;
const int INF = 1e9 + 7;
vector<int> v;
set<int> check;
void solve()
{
v.clear();
check.clear();
int n;
scanf("%d", &n);
v.resize(n);
ff(i , 0 ,n - 1) scanf("%d", &v[i]);
if (n == 1)
{
printf("YES\n");
return;
}
check.insert(v[0]);
check.insert(INF);
check.insert(-INF);
ff(i , 1 , n - 1)
{
if (v[i] == v[i-1]) continue;
if (v[i] > v[i-1])
{
auto it = upper_bound(check.begin() , check.end() , v[i-1]);
if (*it < v[i])
{
printf("NO\n");
return;
}
}
if (v[i] < v[i-1])
{
auto it = upper_bound(check.begin() , check.end() , v[i]);
if (*it != v[i-1])
{
printf("NO\n");
return;
}
}
check.insert(v[i]);
}
printf("YES\n");
}
int main()
{
//ios_base::sync_with_stdio(0);
//cin.tie(0);cout.tie(0);
//freopen("X.inp" , "r" , stdin);
//freopen("Y.out" , "w" , stdout);
int t;
scanf("%d", &t);
while(t--) solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGZmKGkgLCBhICwgYikgZm9yKGludCBpID0gYTsgaSA8PSBpbnQoYik7IGkrKykKI2RlZmluZSBSRVAoaSwgYSAsIGIpIGZvcihpbnQgaSA9IGE7IGkgPj0gaW50KGIpOyBpLS0pCiNkZWZpbmUgTVAgbWFrZV9wYWlyCiNkZWZpbmUgUEIgcHVzaF9iYWNrCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHBhaXI8aW50ICxpbnQ+IHBpOwpjb25zdCBsbCBNQVhOID0gMWU2ICsgNzsKY29uc3QgaW50IElORiA9IDFlOSArIDc7CnZlY3RvcjxpbnQ+IHY7CnNldDxpbnQ+IGNoZWNrOwp2b2lkIHNvbHZlKCkKewogICAgdi5jbGVhcigpOwogICAgY2hlY2suY2xlYXIoKTsKICAgIGludCBuOwogICAgc2NhbmYoIiVkIiwgJm4pOwogICAgdi5yZXNpemUobik7CiAgICBmZihpICwgMCAsbiAtIDEpIHNjYW5mKCIlZCIsICZ2W2ldKTsKICAgIGlmIChuID09IDEpCiAgICB7CiAgICAgICAgcHJpbnRmKCJZRVNcbiIpOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGNoZWNrLmluc2VydCh2WzBdKTsKICAgIGNoZWNrLmluc2VydChJTkYpOwogICAgY2hlY2suaW5zZXJ0KC1JTkYpOwogICAgZmYoaSAsIDEgLCBuIC0gMSkKICAgIHsKICAgICAgICBpZiAodltpXSA9PSB2W2ktMV0pIGNvbnRpbnVlOwogICAgICAgIGlmICh2W2ldID4gdltpLTFdKQogICAgICAgIHsKICAgICAgICAgICAgYXV0byBpdCA9IHVwcGVyX2JvdW5kKGNoZWNrLmJlZ2luKCkgLCBjaGVjay5lbmQoKSAsIHZbaS0xXSk7CiAgICAgICAgICAgIGlmICgqaXQgPCB2W2ldKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBwcmludGYoIk5PXG4iKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAodltpXSA8IHZbaS0xXSkKICAgICAgICB7CiAgICAgICAgICAgIGF1dG8gaXQgPSB1cHBlcl9ib3VuZChjaGVjay5iZWdpbigpICwgY2hlY2suZW5kKCkgLCB2W2ldKTsKICAgICAgICAgICAgaWYgKCppdCAhPSB2W2ktMV0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHByaW50ZigiTk9cbiIpOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CgogICAgICAgIH0KICAgICAgICBjaGVjay5pbnNlcnQodltpXSk7CiAgICB9CiAgICBwcmludGYoIllFU1xuIik7Cgp9CgppbnQgbWFpbigpCnsKICAgIC8vaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIC8vY2luLnRpZSgwKTtjb3V0LnRpZSgwKTsKICAgIC8vZnJlb3BlbigiWC5pbnAiICwgInIiICwgc3RkaW4pOwogICAgLy9mcmVvcGVuKCJZLm91dCIgLCAidyIgLCBzdGRvdXQpOwogICAgaW50IHQ7CiAgICBzY2FuZigiJWQiLCAmdCk7CiAgICB3aGlsZSh0LS0pIHNvbHZlKCk7CiAgICByZXR1cm4gMDsKfQo=