#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <cstring>
#include <cassert>
#define rf freopen("in.in", "r", stdin)
#define wf freopen("out.out", "w", stdout)
#define rep(i, s, n) for(int i=int(s); i<=int(n); ++i)
using namespace std;
const int mx = 1e5+10, mod = 1e9+7;

int t, n;
int a[mx*10];
int mark[mx*10];

int main()
{
	//rf;// wf;
	
	scanf("%d", &t);
	while(t--)
	{
		memset(mark, 0, sizeof mark);
		scanf("%d", &n);
		rep(i, 1, n)
			scanf("%d", &a[i]);
		
		if(n == 1)
		{
			cout << "YES\n";
			continue;
		}

		int check = 1;
		rep(i, 1, n-1)
			if(a[i] > a[i+1] and mark[i])
				check = 0;
			else if(a[i] > a[i+1])
				swap(a[i], a[i+1]), mark[i+1] = 1;

		rep(i, 1, n-1)
			if(a[i] > a[i+1])
				check = 0;
		cout << ((check)? "YES\n": "NO\n");
	}
	return 0;
}