fork download
  1. tc = int(input())
  2. while tc:
  3. k = int(input())
  4. words = []
  5. for i in range(k):
  6. words.append(input())
  7. isans = False
  8. for i in range(k):
  9. for j in range(i + 1, k):
  10. temp1 = words[i] + words[j]
  11. temp2 = words[j] + words[i]
  12. if temp1[::-1] == temp1:
  13. print(temp1)
  14. isans = True
  15. break
  16. if temp2[::-1] == temp2:
  17. print(temp2)
  18. isans = True
  19. break
  20. if isans:
  21. break
  22. if not isans:
  23. print(0)
  24. tc -= 1
  25.  
Success #stdin #stdout 0.02s 9016KB
stdin
2
5
aaba
ba
ababa
bbaa
baaba
3
abc
bcd
cde
stdout
abababa
0