import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------

for _ in range(int(input())):
    n = int(input())
    a = list(mapi())
    sm = 0
    i =0
    while i<n:
        if a[i]<0:
            tmp = a[i]
            if i!=n-1:
                while i<n-1 and a[i+1]<0:
                    if a[i+1]>a[i]:
                        tmp = a[i+1]
                    i+=1
            else:
                i+=1
            sm+=tmp
        elif a[i]>0:
            tmp = a[i]
            if i!=n-1:
                while i<n-1 and a[i+1]>0:
                    if a[i+1]>a[i]:
                        tmp = a[i+1]
                    i+=1
            else:
                i+=1
            sm+=tmp
        i+=1
        #print("cd",i)
    print(sm)