#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;

constexpr size_t MAXN = 1e6 + 5;
int t;

unordered_set<int> st;

struct FHQ_Treap
{
	int val[MAXN], heap[MAXN], lt[MAXN], rt[MAXN], sz[MAXN];
	int root, x, y, z, tot;
	inline void Clear() {
		st.clear();
		for (int i = 0; i <= tot; i++)
			val[i] = heap[i] = lt[i] = rt[i] = sz[i] = 0;
		root = x = y = z = tot = 0;
	}
	inline void PushUp(int x) { sz[x] = sz[lt[x]] + sz[rt[x]] + 1; }
	inline int New(int k) { return val[++tot] = k, heap[tot] = rand(), sz[tot] = 1, tot; }
	inline int Merge(int x, int y)
	{
		if (!x || !y) return x + y;
		if (heap[x] < heap[y]) return rt[x] = Merge(rt[x], y), PushUp(x), x;
		else return lt[y] = Merge(x, lt[y]), PushUp(y), y;
	}
	inline void Split(int x, int k, int& u, int& v)
	{
		if (!x) { u = v = 0; return; }
		if (val[x] <= k) u = x, Split(rt[x], k, rt[u], v), PushUp(x);
		else v = x, Split(lt[x], k, u, lt[v]), PushUp(x);
	}
	inline void Insert(int k) { Split(root, k, x, y), root = Merge(x, Merge(New(k), y)); }
	inline void Delete(int k) { Split(root, k - 1, x, y), Split(y, k, y, z), y = Merge(lt[y], rt[y]), root = Merge(x, Merge(y, z)); }
	inline int FindRank(int k, int ans = 0) { return Split(root, k - 1, x, y), ans = sz[x] + 1, root = Merge(x, y), ans; }
	inline int FindKey(int x, int rk)
	{
		if (rk <= sz[lt[x]]) return FindKey(lt[x], rk);
		if (rk == sz[lt[x]] + 1) return val[x];
		return FindKey(rt[x], rk - sz[lt[x]] - 1);
	}
	inline int Pre(int k, int ans = 0) { return Split(root, k - 1, x, y), ans = FindKey(x, sz[x]), root = Merge(x, y), ans; }
	inline int Suc(int k, int ans = 0) { return Split(root, k, x, y), ans = FindKey(y, 1), root = Merge(x, y), ans; }

	inline int Query(int k, int l, int r) {
		Split(root, k, x, y);
		//printf("%d %d %d %d %d %d %d\n", k, l, r, sz[x], sz[y], l + sz[x] + 1, r + sz[y]);
		int ans;
		if (st.count(k)) {
			if (l + sz[x] - 1 == r + sz[y]) ans = 2;
			else if (l + sz[x] - 1 + 2 == r + sz[y]) ans = 3;
			else if (l + sz[x] - 1 == r + sz[y] + 2) ans = 4;
			else ans = -1;
			root = Merge(x, y);
		}
		else {
			if (l + sz[x] + 1 == r + sz[y]) ans = 0;
			else if (l + sz[x] == r + sz[y] + 1) ans = 1;
			else ans = -1;
			root = Merge(x, Merge(New(k), y));
		}
		st.insert(k);
		return ans;
	}
}FT;

int n, b[MAXN];

inline void Solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> b[i];
	int l = 0, r = 0;
	FT.Clear(), FT.Insert(b[1]), st.insert(b[1]);
	for (int i = 2; i <= n; i++) {
		int tmp = FT.Query(b[i], l, r);
		if (tmp == -1) {
			cout << "NO\n";
			return;
		}
		if (tmp == 0) l++;
		if (tmp == 1) r++;
		if (tmp == 2) l++, r++;
		if (tmp == 3) l += 2;
		if (tmp == 4) r += 2;
	}
	cout << "YES\n";
}

signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> t;
	while (t--) Solve();
}
