t = int(input())
for _ in range(t):
    n = int(input())
    arr = list(map(int,input().strip().split()))[:n]

    if arr[0] > 0:
        flag = 1
    else:
        flag = 0
    ans= 0
    change = 0
    for i in range(n):
        if flag == 0:
            if arr[i] < 0:
                ans += change
                change = arr[i]
                flag = 1
            else:
                change = max(change,arr[i])

        else:
            if arr[i] > 0:
                ans += change
                change = arr[i]
                flag = 0
            else:
                change = max(change,arr[i])
        
    ans += change
    print(ans)
