def func(n,l):
    s=i=j=0
    while i<n:
        j=i
        m1=0
        m2=-1000000000
        while i<n and l[i]<0:
            m2=max(m2,l[i])
            i+=1
        if j!=i:
            s+=m2
            #print('m2',m2)
        j=i
        while i<n and l[i]>0:
            m1=max(m1,l[i])
            i+=1
        if j!=i:
            s+=m1
            #print('m1',m1)
    return s


for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    print(func(n,l))