#include<bits/stdc++.h>
using namespace std;
 
#define int                   long long int
#define loop(i,a,b)           for(int i=(int)a;i<(int)b;++i)
#define loopr(i,a,b)          for(int i=(int)a;i>=(int)b;--i)
#define count_1(n)            __builtin_popcountll(n)
#define pb                    push_back
#define pc                    putchar
#define gc                    getchar
#define itoc(c)               ((char)(((int)'0')+c))
#define max(x,y)              ((x>y)?x:y)
#define min(x,y)              ((x<y)?x:y)
#define mid(s,e)              (s+(e-s)/2)
#define vi                    vector<int>
#define vvi                   vector<vector<int>>
#define pii                   pair<int,int>
const int MOD = 1000000007;
 
int modpow(int a, int b, int mod) { int res = 1; for (; b; b >>= 1) { if (b & 1)res = res * a; res %= mod; a = a * a; a %= mod; }return res; }
int p(int a, int b) { int res = 1; for (; b; b >>= 1) { if (b & 1)res = res * a; a = a * a; }return res; }
int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }


void testcases(int test) {
    int n; cin>>n;
    vi a(n); loop(i,0,n) cin>>a[i];
    set<int> meme; meme.insert(a[0]);
    int flag = 1;
    loop(i,1,n) {
        if(a[i] == a[i-1]) continue;
        auto it1 = meme.begin(), it2 = meme.begin();
        if(a[i] < a[i-1]) { it1 = meme.upper_bound(a[i]); it2 = meme.lower_bound(a[i-1]); }
        else { it1 = meme.lower_bound(a[i]); it2 = meme.upper_bound(a[i-1]); }
        if(it1 != it2) { flag = 0; break; }
        meme.insert(a[i]);
    }
    if(flag) cout << "YES\n";
    else cout << "NO\n";
}     
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t; 
    cin >> t;
    // t = 1;
    loop(i,0,t) testcases(i);
}