t = int(input())
A = []
def T(a):
    if(a<0):
        return True
    else:
        return False
for tests in range(t):
    n = int(input())
    A.clear()
    A = input().split()
    for i in range(n):
        A[i] = int(A[i])
    ans = 0
    maxs = A[0]
    for i in range(1,n):
        if(T(A[i])==T(A[i-1])):
            if(A[i]>maxs):
                maxs = A[i]
        else:
            ans = ans + maxs
            #print("+ %d" % (maxs))
            maxs = A[i]
    ans = ans + maxs
    print(ans)
