#K92162. Common Delivery Locations

    ID: 38137 Type: Default 1000ms 256MiB

Common Delivery Locations

Common Delivery Locations

A transportation company needs to determine the common delivery locations between pairs of drivers. For each test case, you are given two lists representing the delivery locations of two drivers. Your task is to find the intersection of these two lists. The common locations should be output in sorted order (ascending). If there are no common locations, output -1.

Formally, given two sets of locations \(A\) and \(B\), you are to compute the set \(A \cap B\). If \(A \cap B = \emptyset\), output -1; otherwise, output the elements of \(A \cap B\) in increasing order.

inputFormat

The first line of input contains an integer \(T\) representing the number of test cases.

For each test case, the input is given in the following format:

  n
  a1 a2 ... an
  m
  b1 b2 ... bm

Where \(n\) is the number of locations in the first driver's route, followed by \(n\) integers. Then, \(m\) is the number of locations in the second driver's route, followed by \(m\) integers.

outputFormat

For each test case, output a single line. If there are common delivery locations between the two drivers, print them in increasing order separated by a space. Otherwise, print -1.

## sample
2
4
5 1 3 2
5
3 7 5 8 9
3
1 2 3
3
4 5 6
3 5

-1

</p>