t = int(input())
for _ in range(t):
    n = int(input())
    pnt = 0
    A = list(map(int, input().split()))
    sign = 0
    X = []
    X.append(A[0])
    if A[0] > 0:
        sign = 1
    else:
        sign = -1
    for i in range(1, n):
        if A[i] * X[pnt] > 0:
            if X[pnt] < A[i]:
                X[pnt] = A[i]
        else:
            X.append(A[i])
    print(sum(X))