# -*- coding: utf-8 -*-
"""
Created on Tue Apr 21 20:37:38 2020

@author: KSHITIZ ARORA
"""

import sys
msg = sys.stdin.readlines()

l = []

for i in msg:
    l.append (list (map (int, i.split())))
    
def opp(a,b):
    if a>0 and b<0:
        return True
    elif a<0 and b>0:
        return True
    else:
        return False
    
def altsub(l):
    ls = []
    a = l[0]
    for i in l[1:]:
        if opp(a, i):
            ls.append (a)
            a = i
        elif a > 0 and i > a:
            a = i
        elif a < 0 and i > a:
            a = i
    ls.append (a)
    ans = sum_l(ls)
    return ans

def sum_l (l):
    a=0
    for i in l:
        a+=i
    return a

for i in range (l[0][0]):
    ls = l[2*i +2]
    print (altsub(ls))
    