for i in range(int(input())): n = int(input()) L = list(map(int,input().split())) print(min(L), max(L))