''' 如果牌的种类大于1,且只有1种牌的数量大于1张:我们需要预知足够多的卡牌,使得剩下未预知的卡牌中,每种的数量最多为1。这样剩下的牌无论怎么选两张都不会相同,此时玩家只需要从剩下的牌里翻牌。 如果牌的种类大于1,且每种牌的数量都大于1张:需要预知数量最多的种类的所有牌,然后玩家从已预知的牌里抽1张,从未预知的牌里抽1张,即可保证不输。 ''' while True: try: T = int(input()) for i in range(T): n = int(input()) lst = list(map(int, input().split())) if len(lst) == 1: # 只有1种牌 print(-1) elif len(lst) > 1 and min(lst) == 1 and max(lst) == 1: # 每种牌都只有1张 print(0) elif lst.count(1) == len(lst) - 1: # 只有1种牌的数量大于1张 print(max(lst) - 1) else: # 所有种类牌的数量都大于1张 print(max(lst)) except: break