Chef recently developed an affinity for undirected graphs.
He likes pairs of graphs that are similar in structure.
However, Chef discovered that when the vertices of a graph are reorganized, it's often the case that the resulting graph,
although still structurally similar to the original, can look completely different.
Chef wants you to help him find similarities in pairs of graphs.

Chef only considers pairs of graphs where each graph has the same number of vertices (say N).
Chef then labels each vertex of each graph with an integer between 1 and N (inclusive),
using each integer exactly once per graph.
Chef then defines the similarity of the graphs as 2*COMMON/TOTAL, where COMMON is the number of
edges appearing in both graphs 
(that is, the number of unordered pairs {A, B} such that in both graphs there exists an edge between the vertex labelled A
and the vertex labelled B), and TOTAL is the total number of edges in both graphs.

Chef's measure of similarity depends on how the vertices are labelled.
Chef wants you to help him find a labelling that maximizes the similarity.
Optimal solutions are not required, but better solutions will earn more points.

-----Input-----

Input will begin with an integer T, the number of test cases.
Each test case will begin with an integer N, the number of vertices in both graphs.
2*N lines follow.  The first N lines describe the first graph, and the next N lines the second graph.
Each graph description consists of N lines of N integers each.
The i-th integer on the j-th line will be 1 if there is an edge between vertices i and j, and 0 otherwise.
The i-th integer on the j-th line will always be equal to the j-th integer on the i-th line,
and the i-th integer on the i-th line will always be 0.

-----Output-----

For each test case, output 2 lines with N integers each.
Each line must contain a permutation of the integers 1 through N, and indicates how Chef should label the corresponding graph.

-----Scoring-----

Your score for each test case is the similarity of the 2 graphs using the labelling you provide.
Your overall score is the average of your scores on the individual test cases.

-----Sample Input-----
2
3
0 1 0
1 0 0
0 0 0
0 0 1
0 0 1
1 1 0
4
0 0 1 0
0 0 0 0
1 0 0 1
0 0 1 0
0 0 1 1
0 0 0 0
1 0 0 0
1 0 0 0

-----Sample Output-----
1 2 3
1 2 3
1 4 2 3
2 4 1 3

This output would score 2*0/3 = 0.0 on the first test case, and 2*2/4 = 1.0 on the second test case, for an overall score of 0.5.
Note that better scores are possible.

-----Test case generation-----

For each official test file, T is 5.
For each test case, N is randomly chosen between 30 and 75.
A real number D is randomly chosen between 0.05 and 0.5.
For each pair of vertices, an edge is added with probability D.
This graph is output as the first graph.
An integer C is randomly chosen between 0 and N*(N-1)/2.
C distinct pairs of vertices are chosen.
For each pair, if an edge currently exists between them, the edge is removed with probability (1-D).
If no edge exists between them, one is added with probability D.
Then, a random permutation is applied to the vertices of the graph, and it is output as the second graph.
You may safely assume there will be no test cases where TOTAL is 0.

Difficulty: interview

Starter code:

Solutions:
import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random

tc = int(input())
while tc:
	graph1 = []
	graph2 = []
	n = int(input())

	for i in range(n):
		graph1.append([int(x) for x in input().split()])
	for i in range(n):
		graph2.append([int(x) for x in input().split()])

	# Begin LOL
	for x in range(2):
		a = []
		op = ''
		for i in range(n):
			a.append(i+1)

		k = n-1
		while k:
			index = random.randint(0,k-1)
			op += str(a[index]) + ' '
			a.pop(index)
			k -= 1
		op += str(a[0])
		print(op)
	# End LOL
	
	tc -= 1

import random

tc = int(input())
while tc:
	graph1 = []
	graph2 = []
	n = int(input())

	for i in range(n):
		graph1.append([int(x) for x in input().split()])
	for i in range(n):
		graph2.append([int(x) for x in input().split()])

	# Begin LOL
	for x in range(2):
		a = []
		op = ''
		for i in range(n):
			a.append(i+1)

		k = n-1
		while k:
			index = random.randint(0,k-1)
			op += str(a[index]) + ' '
			a.pop(index)
			k -= 1
		op += str(a[0])
		print(op)
	# End LOL
	
	tc -= 1

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<6) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[]
	array2=[]
	array=[]
	for i in range(n) :
		array1.append(list(map(int,input().split())))
	for i in range(n) :
		array2.append(list(map(int,input().split())))
	for i in range(n) :
		array.append(i)
#	print array2,"     ",array1
	for i in range(n) :
		print(array[i]+1, end=' ') 
	print() 
	k=0
	max=0
	answer=[]
	temp=[]
	while k < (1<<5) :
		k+=1	
		for i in range(n) :
			rand=random.randint(0,len(array)-1)
			temp.append(array[rand])
			array.pop(rand)
		array = temp
		count=0
		for i in range(n) :
			for j in range(n) :
				if(array1[i][j] and array2[array[i]][array[j]]) :
					count+=1
		if(count > max):
			answer=array
			max=count
			#print max,count
	for x in answer :
		print(x+1, end=' ')
	print()

t = int(input())
a=[]
while t>0:
    a=[]
    b=[]
    n= int(input())
    for i in range(n):
        k = list(map(int, input().split()))
        z=0
        for j in k:
            z=2*z+j
        a.append(z)
    for i in range(n):
        k = list(map(int, input().split()))
        z=0
        for j in k:
            z=2*z+j
        b.append(z)
    aindex=list(range(n))
    bindex=list(range(n))
    c=aindex
    for i in range(n):
        c[i]=0
    
    for i in range(n):
        for j in range(n-i-1):
            if a[j]>a[j+1]:
                tmp=a[j]
                a[j]=a[j+1]
                a[j+1]=tmp
                tmp=aindex[j]
                aindex[j]=aindex[j+1]
                aindex[j+1]=tmp
            if b[j]>b[j+1]:
                tmp=b[j]
                b[j]=b[j+1]
                b[j+1]=tmp
                tmp=bindex[j]
                bindex[j]=bindex[j+1]
                bindex[j+1]=tmp
    bfinal= list(range(n))
    afinal= list(range(n))
    for i in range(n):
        afinal[aindex[i]]=i+1
        bfinal[bindex[i]]=i+1
    
    """
    for i in range(n):
        max=-1
        maxindex =0
        for j in range(n):
            temp=~(a[i]^b[j])
            if temp>max and c[j]==0:
                max = temp
                maxindex=j
        bindex[maxindex]=i+1          
        c[maxindex]=1"""
    for i in afinal:
        print(i, end=' ')
    print() 
    for j in bfinal:
        print(j, end=' ')
    print()        
    t =  t-1

t = int(input())
a=[]
while t>0:
    a=[]
    b=[]
    n= int(input())
    for i in range(n):
        k = list(map(int, input().split()))
        z=0
        for j in k:
            z=2*z+j
        a.append(z)
    for i in range(n):
        k = list(map(int, input().split()))
        z=0
        for j in k:
            z=2*z+j
        b.append(z)
    aindex=list(range(n))
    bindex=list(range(n))
    c=aindex
    for i in range(n):
        c[i]=0
    
    for i in range(n):
        max=-1
        maxindex =0
        for j in range(n):
            temp=~(a[i]^b[j])
            if temp>max and c[j]==0:
                max = temp
                maxindex=j
        bindex[maxindex]=i+1          
        c[maxindex]=1
    for i in range(n):
        print(i+1, end=' ')
    print() 
    for j in bindex:
        print(j, end=' ')
    print()        
    t =  t-1

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[0]*n
	array2=[0]*n
	for i in range(2*n) :
		array=input()
	for i in range(n) :
		array1[i]=array2[i]=i+1
#	print array2,"     ",array1
	for i in range(n) :
		rand=random.randint(0,len(array1)-1)
		print(array1[rand], end=' ')
		array1.pop(rand) 
	print() 
	for i in range(n) :
		rand=random.randint(0,len(array2)-1)
		print(array2[rand], end=' ')
		array2.pop(rand)
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[0]*n
	array2=[0]*n
	for i in range(2*n) :
		array=input()
	for i in range(n) :
		array1[i]=array2[i]=i+1
#	print array2,"     ",array1
	for i in range(n) :
		rand=random.randint(0,len(array1)-1)
		print(array1[rand], end=' ')
		array1.pop(rand) 
	print() 
	for i in range(n) :
		rand=random.randint(0,len(array2)-1)
		print(array2[rand], end=' ')
		array2.pop(rand)
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[0]*n
	array2=[0]*n
	for i in range(2*n) :
		array=input()
	for i in range(n) :
		array1[i]=array2[i]=i+1
#	print array2,"     ",array1
	for i in range(n) :
		rand=random.randint(0,len(array1)-1)
		print(array1[rand], end=' ')
		array1.pop(rand) 
	print() 
	for i in range(n) :
		rand=random.randint(0,len(array2)-1)
		print(array2[rand], end=' ')
		array2.pop(rand)
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[0]*n
	array2=[0]*n
	for i in range(2*n) :
		array=input()
	for i in range(n) :
		array1[i]=array2[i]=i+1
#	print array2,"     ",array1
	for i in range(n) :
		rand=random.randint(0,len(array1)-1)
		print(array1[rand], end=' ')
		array1.pop(rand) 
	print() 
	for i in range(n) :
		rand=random.randint(0,len(array2)-1)
		print(array2[rand], end=' ')
		array2.pop(rand)
	print()

import random
t=int(input())
for testCase in range(t):
	n=int(input())
	array1=[0]*n
	array2=[0]*n
	for i in range(2*n) :
		array=input()
	for i in range(n) :
		array1[i]=array2[i]=i+1
#	print array2,"     ",array1
	for i in range(n) :
		rand=random.randint(0,len(array1)-1)
		print(array1[rand], end=' ')
		array1.pop(rand) 
	print() 
	for i in range(n) :
		rand=random.randint(0,len(array2)-1)
		print(array2[rand], end=' ')
		array2.pop(rand)
	print()