Teacher gives a mental ability question to Raju . The question is as follows:-

Raju is in an elevator. Given by his teacher is an array of size N which denotes the number of floors and has a 1 based indexing. The elevator starts from the ground and moves up and down, X and Y floors respectively. There is a code used in the elevator according to which it moves up X floors given at odd indexes of the array and moves down Y floors given at even indexes of the array. He is asked to go to the highest floor possible. Help him to sort the array such that he reaches the highest floor after traversing the whole array from starting till the end, without skipping any index.

He always prefers to move more number of floors up and less number of floors down. Once he gets into the elevator, the elevator should not reach the ground again, if it does print “Not Possible”.

**Input:**

The first line of input contains an integer T denoting the number of test cases. T test cases follow. The first line of each test case contains N denoting size of the array. The second line of each test case contains elements of the array separated by a single space.

**Output:**

For each test case, print the sorted array or “Not Possible”.

**Constraints:**

1 ≤ T ≤ 10

1 ≤ N ≤ 1000

1 ≤ X , Y ≤ 1000

**Example:**

Input:

2

4

2 3 4 5

2

1 1

Output:

5 2 4 3

Not Possible

**Explanation:**

**Case 1:**

Array can be arranged as {5,3,4,2} or {4,3,5,2} or {4,2,5,3} but it will get arranged as {5,2,4,3} because he always prefer to move more number of floors up and less number of floors down.

**Case 2:**

Not possible.

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.

VivSisMMM | 164 |

d_Coder00 | 163 |

ajayjadhav35 | 153 |

Astikeysingh | 148 |

Sathvik Avasarala | 143 |

Pulkit__Sharma__ | 658 |

Anirban166 | 565 |

abducodes | 542 |

Sathvik Avasarala | 506 |

Found_me | 494 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.