#P2436. 钦定

钦定

Description

Xiao S got the roster for the semifinals. The contestants on the list are arranged by repeating cycles of AA pros and BB noobs.

For example, when A=2A = 2, B=3B = 3, contestants 1,2,6,7,11,121, 2, 6, 7, 11, 12\dots are pros, and contestants 3,4,5,8,9,10,13,14,153, 4, 5, 8, 9, 10, 13, 14, 15\dots are noobs.

Now Xiao S has designated some contestants as pros and some as noobs, but she cannot construct such A,BA, B. Can you help her?

Input Format

The first line contains an integer TT, the number of test cases.

For each test case:

  • The first line contains two integers N,MN, M.
  • The second line contains NN distinct integers a1,a2,,aNa_1, a_2, \dots, a_N, the contestant indices designated as pros.
  • The third line contains MM distinct integers b1,b2,,bMb_1, b_2, \dots, b_M, the contestant indices designated as noobs.

Output Format

For each test case, output two integers A,BA, B (separated by a space) that satisfy the requirements. Among all valid pairs, choose the one with the smallest AA, and if there are multiple, the one with the smallest BB. If no such A,BA, B exist, output NO.

10 1
4 8 55 56 57 63 64 67 70 150
87
20 2

Hint

Let there be TT test cases in a test file.

  • For 10%10\% of the testdata, 1N,M101 \le N, M \le 10.
  • For 30%30\% of the testdata, 1N,M1001 \le N, M \le 100.
  • For 100%100\% of the testdata, 1N,M10001 \le N, M \le 1000, 1T101 \le T \le 10, 1ai,bi10×(N+M)1 \le a_i, b_i \le 10 \times (N + M).

Translated by ChatGPT 5