t=int(input())
for p in range(t):
    a=list(map(int,input().split()))
    n=len(a)
    count=0
    for i in range(n-1):
        if a[i]*a[i+1]>0:
            a[i+1]=max(a[i],a[i+1])
        else:
            count+=a[i]
            a[i+1]=min(a[i],a[i+1])
    if a[n-1]*a[n-2]>0:count+=max(a[n-1],a[n-2])
    else:count+=a[n-1]+a[n-2]
    print(count)