Associated Course(s):
Must Do Interview Preparation
Sudo Placement 2019

Given two arrays of integers, write a program to check if a pair of values (one value from each array) exists such that swapping the elements of the pair will make the sum of two arrays equal.

**Input:**

First line of input contains a single integer **T** which denotes the number of test cases. T test cases follows. First line of each test case contains two space separated integers **N** and **M**. Second line of each test case contains N space separated integers denoting the elements of first array. Third line of each test case contains M space separated integers denoting the elements of second array.

**Output:**

For each test case, print **1** if there exists any such pair otherwise print **-1**.

**Constraints:**

1 <= T <= 100

1 <= N <= 10^{4}

1 <= M <= 10^{4}

0 <= elements <= 10^{4}

**Example:
Input:**

2

6 4

4 1 2 1 1 2

3 6 3 3

4 4

5 7 4 6

1 2 3 8

**Output:**

1

1

**Explanation:
Testcase 1:** 1 and 3 are two such values one from first array other from second one, if we swap these two values then we will get both arrays sum as equal.

Author: harsh.agarwal0

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.

hardikJain5 | 110 |

CodeBuddy | 107 |

Akkki111 | 100 |

saurabhgrade1 | 98 |

WrongAnswer | 80 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

SumitSingh27 | 1103 |

mazumderrohit8 | 1095 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4566 |

Quandray | 4444 |

Login to report an issue on this page.