Fair Pairing

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
It's final exam week of Chef's cooking class. His class of N students are busy studying for it. Unfortunately, being crammers, each student is only able to study one topic. The ith student studied topic S_{i}. Topics are numbered 1 to 10^{6}.
Chef prepared N tasks for exam. He intends to assign each task to exactly one student. Each task requires exactly one topic to pass. The jth task requires topic T_{j}.
Chef is a sadistic teacher, he doesn't want the students to pass! Therefore he wants to assign the tasks in such that the number of students assigned to the topic he/she studied for is minimized. Can you please help Chef in finding any such assignment?
If there are multiple possible assignments, you may output any one.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N.
The second line contains N spaceseparated integers S_{1}, S_{2}, ..., S_{N}.
The third line contains N spaceseparated integers T_{1}, T_{2}, ..., T_{N}.
Output
For each test case, output two lines.
The first line should contain a single integer denoting the minimum number of students assigned to the topic he/she studied for, i.e. number of students who passed the exam.
The second line should describes assignment. It should contain N space separated integers  a_{1}, a_{2}, ..., a_{N}, meaning the ith student is assigned to the a_{i}th task.
Constraints
 1 ≤ T ≤ 10^{5}
 1 ≤ N ≤ 10^{3}
 The sum of the Ns in a single test file is ≤ 3×10^{5}
 1 ≤ S_{i} ≤ 10^{6}
 1 ≤ T_{j} ≤ 10^{6}
Example
Input: 2 4 100 200 300 400 200 200 300 400 3 100 100 200 100 100 200 Output: 0 2 3 4 1 1 2 3 1
Explanation
Example case 1. Here, there exists an assignment where no student is assigned to the topic he/she studied for:
 Student 1 gets task 2,
 Student 2 gets task 3,
 Student 3 gets task 4,
 Student 4 gets task 1.
Example case 2. In this test case, there's no way we can avoid at least one student from being assigned the topic he/she studied for. But the sample output shows that the minimum in this case is 1:
 Student 1 gets task 2 (and thus gets the topic he/she studied for),
 Student 2 gets task 3,
 Student 3 gets task 1.
Author:  kevinsogo 
Tester:  
Editorial  http://discuss.codechef.com/problems/FAIRPAIR 
Tags  easy, greedy, kevinsogo, snckpb16 
Date Added:  31052016 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 