import sys
from collections import defaultdict as dd
import math
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def l(): return list(sp())
def strl(): return list(strsp())
def sp(): return map(int, data().split())
def strsp(): return map(str, data().split())

for _ in range(int(data())):
    n=int(data())
    a=l()
    k,d,c=0,0,a[0]
    if a[0]<0:
        k=1
    for i in range(1,n):
        if a[i]>0:
            if k==0:
                c=max(a[i],a[i-1],c)
            else:
                d+=c
                k=0
                c=a[i]
        else:
            if k==1:
                c=max(a[i],a[i-1],c)
            else:
                d+=c
                k=1
                c=a[i]
    print(d+c)
            