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.

VISHESHA SADU | 27 |

ghanshyam648 | 25 |

Biswajit3 | 21 |

karthik_kasaragadda | 20 |

tanya_sharma | 18 |

KshatriyaYash | 1066 |

nikhil_sojan | 978 |

lonecoder | 935 |

mazumderrohit8 | 864 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4468 |

Quandray | 4444 |

Login to report an issue on this page.