t = int(input())

for _ in range(t):
    n = int(input())
    arr = list(map(int,input().split()))
    def sign(num):
        return num>0
    ans = 0
    i = 0
    while i<n:
        j = i
        mx = arr[i]
        while(j < n and sign(arr[i])==sign(arr[j])):
            mx = max(arr[j],mx)
            j+=1
        i = j-1
        ans+=mx
        i+=1
    print(ans)
