for i in range(int(input())):
    g = int(input())
    A = list(map(int, input().split()))
    a = A[0]
    su = 0
    for j in range(1, len(A)):
        if a * A[j] > 0:
            if A[j] > a:
                a = A[j]
        else:
            su += a
            a = A[j]
    su += a
    print(su)
