t=int(input())
ans=[]
for k in range(t):
    n=int(input())
    seq=list(map(int,input().split()))
    result=0
    high=float('-inf')
    if seq[0]>0:
        dir=-1
    else:
        dir=1
    for i in range(n):
        if seq[i]<0 and dir<0:
            dir=1
            result+=high
            high=seq[i]
        elif seq[i]>0 and dir>0:
            dir=-1
            result+=high
            high=seq[i]
        else:
            if seq[i]>high:
                high=seq[i]
    ans.append(result+high)
for i in ans:
    print(i)
