t = int(input())
for _ in range(t):
    n = int(input())
    arr = list(map(int,input().split()))
    i,ans = [0]*2
    while i < n:
        if arr[i] < 0:
            mini = arr[i]
            while i < n and arr[i] < 0:
                if arr[i] >= mini:
                    mini = arr[i]
                i += 1
            ans += mini
        else:
            flag = True
            maxi = arr[i]
            while i < n and arr[i] > 0:
                if arr[i] >= maxi:
                    maxi = arr[i]
                i += 1
            ans += maxi
    print(ans)
