# alternating subsequence    DP   Codeforces
t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    currmax=l[0]
    sum=0
    for j in range(n):
        if(l[j]*currmax<0):
            sum+=currmax
            currmax=l[j]
        else:
            currmax=max(currmax,l[j])
    print(sum+currmax)