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