fork download
  1. T = int(input())
  2. for z in range(T):
  3. N = int(input())
  4. lst = list(map(int, input().split()))
  5. idx = -999
  6. for i in range(N-2,-1,-1):
  7. if lst[i] < lst[i+1]:
  8. idx = i
  9. break
  10. if idx == -999:
  11. print(-1)
  12. continue
  13. j = idx + 1
  14. while j < N:
  15. if lst[j] <= lst[idx]:
  16. break
  17. j += 1
  18. lst[idx] , lst[j-1] = lst[j-1], lst[i]
  19. arr = lst[idx+1:]
  20. arr.sort()
  21. tmp = lst[:i+1] + arr[:]
  22. print(*tmp,sep = "")
  23.  
Runtime error #stdin #stdout #stderr 0.16s 23460KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
EOFError: EOF when reading a line