Given two sorted arrays **P[]** and **Q[]** in non-decreasing order with size **X** and **Y**. The task is to merge the two sorted arrays into one sorted array (in non-decreasing order).

**Note: **Expected time complexity is O((X+Y) log(X+Y)). Try not to use extra space.

**Input:**

First line contains an integer **T**, denoting the number of test cases. First line of each test case contains two space separated integers **X**** and Y**, denoting the size of the two sorted arrays. Second line of each test case contains **X** space separated integers, denoting the first sorted array P. Third line of each test case contains **Y** space separated integers, denoting the second array Q.

**Output:**

For each test case, print (**X**** + Y**) space separated integer representing the merged array.

**Constraints:**

1 <= **T** <= 100

1 <= **X****, Y** <= 5*10^{4}

0 <= **P**** _{i}**,

**Example:**

**Input:**

1

4 5

1 3 5 7

0 2 6 8 9

**Output:**

0 1 2 3 5 6 7 8 9

**Explanation:
Testcase 1: **After merging two non-decreasing arrays, we have, 0 1 2 3 5 6 7 8 9.

blackshadows | 210 |

xmyqsh | 198 |

hanuman001 | 164 |

Adarsh Trivedi | 148 |

layman_brother | 144 |

blackshadows | 692 |

xmyqsh | 539 |

aman19 | 398 |

r0c2048 | 360 |

kspk | 331 |

akhayrutdinov | 5005 |

Ibrahim Nash | 4871 |

Quandray | 4338 |

sanjay05 | 3668 |

blackshadows | 3196 |

Login to report an issue on this page.