import math
import sys
from collections import defaultdict
from collections import Counter
from collections import deque
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]

for _ in range(int(input())):
    N = int(input())
    A = alele()
    i = 0;B = [];temp = []
    while i<len(A):
        if i != len(A)-1:
            if A[i]<0 and A[i+1]>0 or A[i]>0 and A[i+1] < 0:
                temp.append(A[i])
            else:
                temp.append(A[i])
                B.append(temp)
                temp = []
        else:
            if A[i]<0 and A[i-1]>0 or A[i]>0 and A[i-1] < 0:
                temp.append(A[i])
            else:
                temp = []
                temp.append(A[i])
            B.append(temp)
        i+=1
    #print(B)
    Ans = -1e10;mm = 0
    for i in B:
        if len(i) >= mm:
            Ans = max(Ans,sum(i))
    print(Ans)
        
        
        
        
        
        