'''
Name : Jaymeet Mehta
codeforces id :mj_13
Problem : 
'''
from sys import stdin,stdout
import math
test=int(stdin.readline())
for _ in range(test):
    n=int(stdin.readline())
    a=[int(x) for x in stdin.readline().split()]
    pos=a[0]>0
    i=0
    sum=0
    out=False
    while i<n:
        if pos:
            elem=-1000000001
            while a[i]>0:
                elem=max(elem,a[i])
                i+=1
                if i>=n:
                    out=True
                    break
            sum+=elem
            pos=False
        else:
            elem=-1000000001
            while a[i]<0:
                elem=max(elem,a[i])
                i+=1
                if i>=n:
                    out=True
                    break
            sum+=elem
            pos=True
        if out:
            break
            
    print(sum)