t = int(input())

def isPos(z):
    if z < 0:
        return True
    else:
        return False

for _ in range(t):
    n = int(input())
    a = list(map(int, input().rstrip().split(" ")))

    sumMax = 0
    i = 0
    while i < n:
        if isPos(a[i]):
            mx = a[i]
            while i < n and isPos(a[i]):
                if a[i] > mx:
                    mx = a[i]
                i += 1
            sumMax += mx
        else:
            mn = a[i]
            while i < n and not isPos(a[i]):
                if a[i] > mn:
                    mn = a[i]
                i += 1
            sumMax += mn

    print(sumMax)