from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import sys
input = sys.stdin.readline

M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().split()]
def st():return input()
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input()]
def li3():return [int(i) for i in input()]

def makel(l):
    l1 = []
    curr = l[0]
    par = 1 if l[0] > 0 else 0
    for i in range(1,len(l)):
        currpar = 1 if l[i] > 0 else 0
        if currpar == par:
            curr = max(curr,l[i])
        else:
            l1.append(curr)
            curr = l[i]
            par = 1 - par
    l1.append(curr)
    return l1[:]
for _ in range(val()):
    n = val()
    l = makel(li())
    print(sum(l))