#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline
from collections import deque


t=int(input())
for ii in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    ans=0
    if max(l)<0 or min(l)>0:
        print(max(l))
        continue
    if l[0]>0:
        f=1
    else:
        f=-1
    m=l[0]
    z=[]
    for i in range(n-1):
        if l[i]*l[i+1]<0:
            z.append(max(m,l[i]))
            m=-10**10
        else:
            m=max(m,l[i])
    if l[-1]*z[-1]>0:
        z[-1]=max(z[-1],max(m,l[-1]))
    else:
        z.append(max(m,l[-1]))
    # print(z)
    print(sum(z))
sys.exit()

N = 5
es = [[1,2,3],[0,2],[0,1],[0,4],[3]] # False
#es = [[1,3],[0,2],[1,3],[0,2,4],[3]] # True
colors = [0 for i in range(N)]
def dfs(v,color):
    print(v,color)
    colors[v] = color
    for to in es[v]:
        if colors[to] == color:
            return False
        if colors[to] == 0 and not dfs(to, -color):
            return False
    return True

def is_bipartite():
    return dfs(0,1)
print(is_bipartite())





