from sys import stdin,stdout
for testcases in range(int(stdin.readline())):
    n=int(stdin.readline())
    arr=list(map(int,stdin.readline().split()))
    total=0
    local=arr[0]
    for i in range(1,n):
        if arr[i] * arr[i-1]>0:
            local=max(arr[i],local)
 
        else:
            total+=local    
            local=arr[i]
    if arr[n-1] * arr[n-2]>0:
        total+=local
    else:
        total+=arr[n-1]
    stdout.write(str(total)+'\n')
    