Ishaan being curious as always, was playing with numbers when he started to reversing the numbers. He invented something called the "inverting factor" of two numbers.

Inverting Factor of 2 integers is defined as the absolute difference between the reverse of the 2 integers.

Ishaan has an array A of N integers. He wants to find out the smallest possible Inverting Factor among all pairs of his integers. Help him find that.

**Note :** Trailing zeros in a number of ignored while reversing, i.e. 1200 becomes 21 when reversed.

**Input : **

First line of input contains a single integer T denoting the number of test cases.

The first line of each test case contains an integer N.

The second line contains N space-separated integers denoting the array A.

**Output : **

For each test case, print the required answer in a new line.

**Constraints : **

1 <= T <= 100

2 <= N <= 1000

1 <= A[i] <= 10^5

**Example :
Input : **

3

5

56 20 47 93 45

6

48 23 100 71 56 89

4

26 15 45 150

9

14

0

**Explanation : **

Case 1 :

The minimum inverting factor is 9, of the pair (56,47)

Case 2 :

The minimum inverting factor is 14, of the pair (48,89)

Case 3 :

The minimum inverting factor is 0, of the pair (15,150)

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.

makeitdonesolo | 64 |

ShubhamJain18 | 64 |

Bishnu Dev Panda | 54 |

DanishBansal | 50 |

abhithakur588 | 50 |

Bishnu Dev Panda | 777 |

yk12 | 512 |

okayboss | 490 |

DevMittal | 472 |

VijethaShastri | 431 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.