from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
import bisect as bi
import heapq 
'''
#------------------PYPY FAst I/o--------------------------------#
 
def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
'''
#------------------Sublime--------------------------------------#
 
#sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))


def main():
    try:
        for _ in range(I()):
            n=I()
            l=list(In())
            d=[]
            prim=l[0]
            for x in range(1,n):
                if l[x]<0 and prim<0:
                    prim=min(abs(l[x]),abs(prim))
                    prim=-1*prim
                elif l[x]>0 and prim>0:
                    prim=max(l[x],prim)
                else:
                    d.append(prim)
                    prim=l[x]
            d.append(prim)
            print(sum(d))

            
    except:
        pass
        
M = 998244353
P = 1000000007
 
if __name__ == '__main__':
    main()