'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:21/04/2020

'''
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())


abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def main():
    
    
   
    for _ in range(ii()):
        n=ii()
        a=li()
        f,f1=0,0
        ans=0
        x=-mod
        y=-mod
        for i in range(n):
            if(a[i]>=0):
                x=max(x,a[i])
                f=1
                if(f1==1):
                    # print(y)
                    ans+=y
                    y=-mod
                    f1=0
            else:
                y=max(y,a[i])
                f1=1
                if(f==1):
                    # print(x)
                    ans+=x
                    x=-mod
                    f=0
        if(f==1):
            ans+=x
        if(f1==1):
            ans+=y
        print(ans)
        
        


    

if __name__ == "__main__":
    main()