#include<bits/stdc++.h>
using namespace std;
//----------------自定义部分----------------
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair<int,int>
#define INF 0x3f3f3f3f

int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

ll ksm(ll a,ll b) {
	ll ans = 1;
	for(;b;b>>=1LL) {
		if(b & 1) ans = ans * a % mod;
		a = a * a % mod;
	}
	return ans;
}

ll lowbit(ll x){return -x & x;}

const int N = 2e6+10;
//----------------自定义部分----------------
int t,n,m,q,a[N],b[N],c[N],d[N];
void slove(){
	cin>>n;
	for(int i = 1;i <= n; ++i) {
		cin>>a[i];
		b[i] = a[i];
	}
	for(int i = 1;i <= n; ++i) cin>>c[i],d[i] = c[i];
	sort(b+1,b+1+n);
	sort(d+1,d+1+n);
	for(int i = 1;i <= n; ++i){
		if(b[i] != d[i]){
			cout<<"NO"<<endl;
			return;
		}
	}
	cout<<"YES"<<endl;
	for(int i = 1;i <= n; ++i) {
		int loc = 1;
		for(int j = 1;j <= n; ++j) {
			if(a[j] == c[i]) {
				loc = j;
				break;
			}
		}
		for(int j = loc;j > 1; --j) {
			swap(a[j],a[j-1]);
			cout<<j<<" "<<j-1<<endl;
		}
	}
	cout<<"0 0"<<endl;
	
}

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

0 comments

No comments so far...