import math

def solve():
    n=int(input())
    arr=[int(x) for x in input().split(" ")]
    new_arr=[]
    temp=arr[0]
    for i in range(1,n):
        if arr[i]*arr[i-1]<0:
            new_arr.append(temp)
            temp=arr[i]
            if i==n-1:
                new_arr.append(temp)
        else:
            temp=max(temp,arr[i])
            if i==n-1:
                new_arr.append(temp)
    return sum(new_arr)
            


t=int(input())
for i in range(t):
    ans = solve()
    print(ans)

