from collections import defaultdict as dc
from heapq import *
import math
import bisect
import sys
from collections import deque as dq
from heapq import heapify,heappush,heappop
mod=10**12
def inp(): 
    p=int(input())
    return p
def line():
    p=list(map(int,input().split()))
    return p
def read_mat():
    n=inp()
    a=[]
    for i in range(n):
        a.append(line())
    return a
def digit(n):
    s=str(n)
    p=0
    for i in s:
        p+=(int(i))**2
    return p
    
def check(a,b):
    for i in range(26):
        for j in range(len(a)+1):
            q=a[:j]+chr(97+i)+a[j:]
            if q==b:
                return 1
    return 0
def solve(a,n):
    ans=0
    l=max(a)
    r=min(a)
    if l<0:
        return l
    if r>0:
        return l
    i=0
    while(i<n):
        if a[i]<0:
            l=float('-inf')
            while(i<n and a[i]<0):
                l=max(l,a[i])
                i+=1
            # print(l)
            ans+=l
        else:
            r=float('-inf')
            while(i<n and a[i]>0):
                r=max(r,a[i])
                i+=1
            # print(r)
            ans+=r
    return ans


    
for _ in range(inp()):
    n=inp()
    a=line()
    l=solve(a,n)
    print(l)
    # print("Case #"+str(_+1)+":",l)