Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the triplet in decreasing order. If there are 2 or more smallest difference triplets, then the one with the smallest sum of its elements should be displayed.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Each test case contains number of elements in array a[], b[] and c[] as n and next 3 lines contain space separated n elements in the arrays a[], b[] and c[] respectively.

**Output:**

Output three space separated integers which form the happiest triplet.

**Constraints:**

1<=T<=100

1<=n<=1000

1<= a[i], b[i] ,c[i] <=100000

**Example:
Input:**

2

3

5 2 8

10 7 12

9 14 6

4

15 12 18 9

10 17 13 8

14 16 11 5

7 6 5

11 10 9

Author: shashwat jain

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.