t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    p=0
    tp=a[0]
    ans1=0
    for i in range(1,n):
        if a[i]>0 and a[i-1]>0:
            tp=max(tp,a[i])
        elif a[i]<0 and a[i-1]>0:
            ans1+=tp
            tp=a[i]
        elif a[i]>0 and a[i-1]<0:
            ans1+=tp
            tp=a[i]
        else:
            tp=max(tp,a[i])
    ans1+=tp
    print(ans1)