# cook your dish here
import math
for _ in range(int(input())):
    n=int(input())
    a=[int(i) for i in input().split()]
    b=[]
    ps=0;ns=0
    x=[]
    y=[]
    for i in range(n):
        if(a[i]>0):
            x.append(a[i])
            if(len(y)>0):
                b.append(y)
            y=[]
            ns=0
            ps=1
        if(a[i]<0):
            y.append(a[i])
            if(len(x)>0):
                b.append(x)
            x=[]
            ps=0
    if(len(x)>0):
        b.append(x)
    if(len(y)>0):
        b.append(y)
    c=[]
    for i in range(len(b)):
        c.append(max(b[i]))
    print(sum(c))