t = int(input())

while(t):
    n = int(input())
    arr = list(map(int, input().split()))
    indices = []
    for i in range(n-1):
        if (arr[i]>0 and arr[i+1]<0) or (arr[i]<0 and arr[i+1]>0): indices.append(i+1)
    start = 0
    Sum = 0
    if indices==[]: 
        print(max(arr))
    else:
        for i in indices:
            Sum+=max(arr[start:i])
           # print(arr[start:i])
            start = i
        
        print(Sum+max(arr[indices[-1]:n]))
    
    t-=1
    