#include <iostream>
#include <set>
#include <algorithm>
 
using namespace std;
#define qIO ios_base::sync_with_stdio(false); cin.tie(0)

signed main() {
  qIO;
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    bool check = 1;
    cin >> n;
    int arr[n];
    for (int i=0; i<n; i++) cin >> arr[i];
    set<int> st;
    st.insert(arr[0]);
    for (int i=1; i<n; i++) {
      int prev = arr[i-1];
      if (arr[i] > prev) {
        auto it = st.upper_bound(prev);
        if (it != st.end() && *it < arr[i]) {
          check = 0;
          break;
        }
      } else if (arr[i] < prev) {
        auto it = st.lower_bound(prev);
        if (it != st.begin() && *(--it) > arr[i]) {
          check = 0;
          break;
        }
      }
      st.insert(arr[i]);
    }
    cout << ((check)? "YES\n":"NO\n");
  }
  return 0;
}