8611: Yet Another Sorting Problem!

内存限制:1024 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:9 通过:0

题目描述

There are N persons in Bytetown, with the iii-th person having an item of type Ai. These persons want to exchange items with each other through the following operation:

  • Choose two persons i,j(i≠j), exchange the item owned by the i-th person and the j-th person.

They want to perform this operation exactly once between each pair of persons (i,j) with 1≤i<j≤N. At the end of this sequence of operations, the i-th person wants to own an item of type Bi. They want to know if there exists a sequence of operation achieving this requirement. Can you help them?

输入格式

The first line contains an integer T (1≤T≤104), denoting the number of test cases.
For each test case, the first line contains an integer N(1≤N≤200), denoting the number of persons in Bytetown.
The second line contains N integers A1,A2,…,AN(1≤Ai≤N), where Ai denotes the item initially owned by the i-th person.
The third line contains N integers B1,B2,…,BN(1≤Bi≤N), where Bi denotes the item desired by the i-th person.
It is guaranteed that the sum of N2 does not exceed 4⋅105.

输出格式

For each test case, if there doesn't exist a sequence of operation achieving this requirement, output "NO"(without quotes) in a line. Otherwise, output "YES"(without quotes) in a line, then output a sequence of operation achieving the requirement in N(N−1)/2 lines, where the k(1≤k≤N(N−1)/2)th line contains two integers i,j, denoting the k-th operation in the sequence.

输入样例 复制

2
2
1 2
1 2
2
2 1
1 2

输出样例 复制

NO
YES
1 2