from collections import *
from bisect import *
#from math import *
import sys
input=sys.stdin.readline
t=int(input())
while(t):
    t-=1
    n=int(input())
    a=list(map(int,input().split()))
    r=0
    flag=0
    if(a[0]>0):
        flag=0
        s=-1
    else:
        flag=1
        s=-100000000000000000
    for i in range(n):
        if(flag==0):
            if(a[i]>0):
                s=max(s,a[i])
                continue
            else:
                flag=1
                r+=s
                s=a[i]
        else:
            if(a[i]<0):
                s=max(s,a[i])
                continue
            else:
                flag=0
                r+=s
                s=a[i]
    r+=s
    print(r)
