def solve(): N = int(input()) A = list(map(int, input().split())) tot = sum(A) a = max(A) b = tot - a rest = max(0, a - b - 1) return tot - rest T = int(input()) for _ in range(T): ans = solve() print(ans)