t= int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    pos,neg=[],[]

    if(a[0]>0):
        prev=1
    else:
        prev=0
    ar=[a[0]]
    for i in range(1,len(a)):
        if(prev==0):
            if(a[i]>0):
                ar.append(a[i])
                prev=1
            else:
                if(a[i]>ar[-1]):
                    ar.pop()
                    ar.append(a[i])
        else:
            if(a[i]<0):
                ar.append(a[i])
                prev=0
            else:
                if(a[i]>ar[-1]):
                    ar.pop()
                    ar.append(a[i])
    print(sum(ar))

