///
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N=1e5+5;

template <typename T>
class fenwick {
  public:
    vector<T> fenw;
    int n;

    fenwick(int _n) : n(_n) {
        fenw.resize(n);
    }

    void modify(int x, T v) {
        while (x < n) {
            fenw[x] += v;
            x |= (x + 1);
        }
    }

    T get(int x) {
        T v{};
        while (x >= 0) {
            v += fenw[x];
            x = (x & (x + 1)) - 1;
        }
        return v;
    }
};

fenwick<int>tree(N);

struct Stu {
    int id,a,b;
} stu[N];

int main() {
#ifdef ONLINE_JUDGE
    //std::ios::sync_with_stdio(false);
#else
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif
    int t;
    scanf("%d",&t);
    while(t--) {
        int n;
        scanf("%d",&n);
        for(int i=0; i<n; i++) {
            stu[i].id=i;
            scanf("%d",&stu[i].a);
            stu[i].b=0;
        }
        tree.fenw.clear();
        tree.fenw.resize(N);
        for(int i=0; i<n; i++) {
            stu[i].b+=tree.get(N-3)-tree.get(stu[i].a);
            tree.modify(stu[i].a,1);
        }
        tree.fenw.clear();
        tree.fenw.resize(N);
        for(int i=n-1; i>=0; i--) {
            stu[i].b+=tree.get(stu[i].a-1);
            tree.modify(stu[i].a,1);
        }
        bool f=1;
        sort(stu,stu+n,[](Stu a,Stu b) {
            if(a.a==b.a)return a.id<b.id;
            return a.a<b.a;
        });
        int sum=0,now=-1,len=1;
        for(int i=0; i<n; i++) {
            if(stu[i].a!=now) {
                if(sum)f=0;
                now=stu[i].a;
                len=1;
                if(stu[i].b&1)sum+=len&1?1:-1;
            } else {
                len++;
                if(stu[i].b&1)sum+=len&1?1:-1;
            }
        }
        if(f)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
