while True: try: T = int(input()) res = [] for _ in range(T): n = int(input()) a = list(map(int, input().split())) if n == 1: # 由于总卡牌数是2,当n为1的时候,必败 res.append(-1) else: if max(a) == 1: # 全是1时,说明随便翻两张都必胜 res.append(0) else: if sum([a[i] - 1 for i in range(n)]) == max(a) - 1: # 只有一个大于1时,需要预知max-1 res.append(max(a) - 1) else: # 其他情况 ,因为我们预知max张相同的卡牌后,就知道了剩下的所有卡牌和已经知道的卡牌都是不一样的,从这两堆里各选一张即可。 res.append(max(a)) print(*res, sep="\n") except: break