#include <iostream>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while(T--)
  {
    int n;
    cin >> n;
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    int ones = 0, zeros = 0;
    cout << 1;
    for(int i = 1; i <= n; i++) cout << 0;
    for(int i = 1; i <= n; i++) cout << 1;
    cout << endl;
  }
  return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define N 200005
using namespace std;
int n,a[N],b[N],p[N],ans,sx[N],sy[N],z[N],zz,mx,mxid;
bool vis[N];
void dfs(int x)
{
	if(vis[x])return;
	z[++zz]=x;
	vis[x]=1;
	if(a[x]>mx)
	{
		mx=a[x];
		mxid=x;
	}
	dfs(p[x]);
}
int main()
{
#ifdef lovelyG
Sfile(1);
#endif
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<=n;++i)scanf("%d",&b[i]);
	for(int i=1;i<=n;++i)scanf("%d",&p[i]);
	for(int x,i=1;i<=n;++i)
	{
		if(vis[i])continue;
		zz=mx=0;
		dfs(i);
		x=mxid;
		while(p[x]!=x)
		{
			if(b[p[x]]>=a[x]||b[p[p[x]]]>=a[p[x]])
			{
				puts("-1");
				return 0;
			}
			sx[++ans]=x;
			sy[ans]=p[x];
			swap(p[x],p[p[x]]);
		}
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;++i)
	printf("%d %d\n",sx[i],sy[i]);
	return 0;
}