Given two arrays **L**[] and **R**[] consisting of **N** ranges of the form **L** and **R**, L[i] consists of starting point of range and R[i] consists of corresponding end point of the range. The task is to find the maximum occurred integer in all the ranges. If more than one such integer exits, print the smallest one.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the size of the ranges. The next two lines contain the n space separated elements of L and R respectively.

**Output:**

Print the smallest maximum occured integer in all the ranges.

**Constraints:**

1 <= T <= 10^{5}

1 <= n <= 10^{5}

0 <= L[i], R[i] <= 10^{5}

**Example:
Input:**

2

4

1 4 3 1

15 8 5 4

5

1 5 9 13 21

15 8 12 20 30

**Output:**

4

5

**Explanation:
Testcase 1:** 4 is the most occuring element after considering all the ranges. So, output is 4.

Author: Ayush Govil 1

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.

thanuvinu94 | 238 |

the_coder95 | 215 |

ShivayLamba | 208 |

sandeep.prajapati | 129 |

adityasuman2025 | 111 |

the_coder95 | 1441 |

RishabhTanwar1 | 1110 |

thanuvinu94 | 914 |

tathagat289 | 668 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4897 |

Quandray | 4547 |

Login to report an issue on this page.