#include <stdio.h>
#include <stdlib.h>
inline int compare(const void * p, const void q)
{
struct guest ip=(struct guest*)p;
struct guest* iq=(struct guest*)q;
return( (ip->a)-(iq->a) );
}
struct guest
{
int a;
int d;
} g[100];
int main(void)
{
int t,n,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&g[i].a);
}
for(i=0;i<n;i++)
{
scanf("%d",&g[i].d);
}
qsort(g,n,sizeof(struct guest),compare);
for(i=0;i<n;i++)
{
printf("%d ",g[i].a);
printf("%d\n",g[i].d);
}
}
return 0;
}