BETA

Submissions : 50 Accuracy :

18

Longest repeating and non-overlapping substring
       

Given a string str, find the longest repeating non-overlapping substring in it. In other words find 2 identical substrings of maximum length which do not overlap. If there exists more than one such substring return any of them.

Input:

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the length of the string str.

The second line of each test case contains the string str.It consists of only lower case english alphabets.

Output:

Print the longest non - overlapping substring for each test case in a new line. If no such sub - sequence exists print -1.


Constraints:

1<= T<=100

1<= N <=1000


Example:

Input:

1

13

geeksforgeeks

Output:

geeks

**For More Examples Use Expected Output**


Contributor: Sujnesh Mishra

Set Default Code

					   
Result:
It is recommended to test your code before clicking 'Submit' button!



                   



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.