
if __name__=="__main__":
    for _ in range(int(input())):
        n= int(input())
        arr= list(map(int,input().split()))
        ans=[]
        ans.append(arr[0])
        for i in range(1,n):
            if ans[-1]>0 and arr[i]<0:
                ans.append(arr[i])
            elif ans[-1]>0 and arr[i]>0:
                ans[-1]=max(ans[-1],arr[i])
            elif ans[-1]<0 and arr[i]>0:
                ans.append(arr[i])
            elif ans[-1]<0 and arr[i]<0:
                ans[-1]=max(ans[-1],arr[i])

        print(sum(ans))

