from sys import stdin,stdout
from collections import Counter
from itertools import permutations
import bisect
import math

I=lambda: map(int,stdin.readline().split())
I1=lambda: stdin.readline()
#(a/b)%m =((a%m)*pow(b,m-2)%m)%m

for _ in range(int(I1())):
    n=int(I1())
    a=list(I())
    c=[]
    s=a[0]
    for i in range(1,n):
        if s*a[i]<0:
            c.append(s)
            s=a[i]
        else:
            s=max(s,a[i])
    #print(c)
    if len(c)==0 or c[-1]*s<0:
        c.append(s)
    print(sum(c))
 