#P2436. 钦定
钦定
Description
Xiao S got the roster for the semifinals. The contestants on the list are arranged by repeating cycles of pros and noobs.
For example, when , , contestants are pros, and contestants are noobs.
Now Xiao S has designated some contestants as pros and some as noobs, but she cannot construct such . Can you help her?
Input Format
The first line contains an integer , the number of test cases.
For each test case:
- The first line contains two integers .
- The second line contains distinct integers , the contestant indices designated as pros.
- The third line contains distinct integers , the contestant indices designated as noobs.
Output Format
For each test case, output two integers (separated by a space) that satisfy the requirements. Among all valid pairs, choose the one with the smallest , and if there are multiple, the one with the smallest . If no such exist, output NO.
10 1
4 8 55 56 57 63 64 67 70 150
87
20 2
Hint
Let there be test cases in a test file.
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号