Associated Course(s):
Must Do Interview Preparation

Given two unsorted arrays **A** of size **N** and **B** of size **M** of distinct elements, the task is to find all pairs from both arrays whose sum is equal to **X**.

**Input:**

The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains 3 lines . The first line contains 3 space separated integers N, M, X. Then in the next two lines are space separated values of the array A and B respectively.

**Output:**

For each test case in a new line print the sorted space separated values of all the pairs u,v where u belongs to array A and v belongs to array B, such that each pair is separated from the other by a ',' without quotes also add a space after the ',' . If no such pair exist print **-1**.

**Constraints:**

1 <= T <= 100

1 <= N, M, X <= 10^{6}

-10^{6} <= A, B <= 10^{6}

**Example:
Input:**

2

5 5 9

1 2 4 5 7

5 6 3 4 8

2 2 3

0 2

1 3

1 8, 4 5, 5 4

0 3, 2 1

**Explanation:
Testcase 1: **(1, 8), (4, 5), (5, 4) are the pairs which sum to 9.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

devsinghindra | 80 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 443 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.