//author@nowadays - 2021-06-06  23:18:31
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    int nb = (int) b.size();
    vector<int> f(nb + 1, 0);
    function<void(int, int)> ft_update = [&](int u, int value) {
        while (u <= nb) {
            f[u] += value;
            u += u & -u;
        }
    };
    function<int(int)> ft_get = [&](int u) {
        int ans = 0;
        while (u > 0) {
            ans += f[u];
            u -= u & -u;
        }
        return ans;
    };
    vector<int> ans(n + n - 1);
    int mi = - 1e9 - 1;
    int ma = + 1e9 + 1;
    int ps = 0;
    int wlef = 0;
    int wrig = 0;
    bool good = true;
    for (int i = 0; i < n; ++i) {
        int idx = (int)(lower_bound(b.begin(), b.end(), a[i]) - b.begin()) + 1;
        int lef = ft_get(idx - 1);
        int mid = ft_get(idx) - lef;
        int rig = ft_get(nb) - (mid + lef);
        int cnt = (i == 0 ? 0 : 1);
        if (mid == 0) {
            ft_update(idx, 1);
            ans[ps++] = a[i];
        } else {
            ++cnt;
        }
        while (cnt > 0) {
            if (lef + wlef > wrig + rig) {
                ++wrig;
                ans[ps++] = ma++;
                --cnt;
                continue;
            }
            if (lef + wlef < wrig + rig) {
                ++wlef;
                ans[ps++] = mi--;
                --cnt;
                continue;
            }
            if (lef + wlef == wrig + rig) {
                if (cnt % 2 != 0) {
                    good = false;
                    break;
                }
                ++wlef;
                ++wrig;
                ans[ps++] = mi--;
                ans[ps++] = ma++;
                --cnt;
                --cnt;
                continue;
            }
        }
        if (!good || (lef + wlef != rig + wrig)) {
            good = false;
            break;
        }
    }
    if (good) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    // for (auto i: ans) {
    //     cout << i << " ";
    // }
    // cout << "\n";
}

int main() {
    ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}