#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;
}
