t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    c=0
    ans=0
    cm=arr[0]
    if arr[-1]>0:
        arr.append(-1)
    else:
        arr.append(float("inf"))
    # print(arr)
    for i in range(1,n+1):
        if arr[i]>0 and arr[i-1]<0 or arr[i]<0 and arr[i-1]>0:
            c+=1
            ans+=cm
            if arr[i]>0:
                cm=-1
            else:
                cm=-float("inf")
            if arr[i]>cm:
                cm=arr[i]
            # print("f",i,ans,cm)
        else:
            if arr[i]>cm:
                cm=arr[i]
                # print(i,ans,cm)

    # print(c,ans,cm)
    print(ans)
    # print("ans",ans)