# -*- coding: utf-8 -*-
"""
Created on Tue Apr 21 11:20:05 2020

@author: lucas
"""

t=int(input())

for i in range(t):
    n=int(input())
    a=input().split()
    k=0
    s=0
    a = [int(u) for u in a]
    for j in range(n):
        if(j==0):
            k=a[0]
        else:
            if(k*a[j]>0):
                if(a[j]>k):
                    k=a[j]
                    pass
                pass
            else:
                s+=k
                k=a[j]
                pass
            pass
        pass
    s+=k
    print(s)
    pass
