from collections import Counter
from _collections import defaultdict
import math
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
rls= lambda: list(map(str, input().split()))

t=int(input())
for _ in range(0,t):
    n=int(input())
    a=list(map(int, input().split()))
    mx=-9999999999
    ans=0
    for i in range(0,n):
        if(i==0):
            if(a[i]>0):
                sign=1
                mx=max(mx,a[i])
            else:
                sign=-1
                mx=max(mx,a[i])
        else:
            if(sign==1 and a[i]<0):
                ans=ans+mx
                sign=-1
                mx=a[i]
            elif(sign==-1 and a[i]>0):
                ans=ans+mx
                sign=1
                mx=a[i]
            else:
                mx=max(a[i],mx)
    ans=ans+mx
    print(ans)
