import sys
input = sys.stdin.readline

t=int(input())
for tests in range(t):
    n=int(input())
    A=list(map(int,input().split()))

    NOW=[]
    SUM=0

    for i in range(n):
        if NOW==[]:
            NOW.append(A[i])
            
        elif NOW[0]*A[i]<0:
            SUM+=max(NOW)
            NOW=[A[i]]

        else:
            NOW.append(A[i])

    if NOW!=[]:
        SUM+=max(NOW)

    print(SUM)
            

