#include <bits/stdc++.h>
using namespace std;
int main()
{
int tt;
cin>>tt;
while(tt--)
{
long long i,j,n,x,y;
cin>>n;
vector <pair<int,int > > v(n);
for(i=0; i<n; i++)
{
    cin>>x;
    v[i]={x,i};
}
sort(v.begin(),v.end());
x=1;
for(i=0; i<n; i++)
{
    if(abs(v[i].second-i)%2==0)
        continue;
    j=i+1;
    while(v[i].first==v[j].first and j<n)
    {
        if(abs(v[i].second-v[j].second)%2==1)
        {
            swap(v[i].second, v[j].second);
            break;
        }
        j++;
    }
    if(abs(v[i].second-i)%2==0)
        continue;
    else
    {
        x=0;
        break;
    }
}
if(x==1)
    cout<<"YES"<<endl;
else
    cout<<"NO"<<endl;
}
}
