t=int(input()) def judge(x): s=0 for i in a: s+=min(i,x) return x*2<=s for _ in range(t): n=int(input()) a=[*map(int,input().split())] ok,ng=0,1<<60 while abs(ok-ng)>1: mid=ok+ng>>1 if judge(mid): ok=mid else: ng=mid ans=f=0 for i in a: ans+=min(i,ok) if i>ok: f=1 print(ans+f)