# alternating_subsequence.py

def sign(a):
    return a>0
t = int(input())
while t>0:
    t-=1
    n = int(input())
    a = list(map(int,input().split()))
    ans = 0
    i = 0
    while i<n:
        max_ = a[i]
        j = i
        while(j<n and sign(a[i]) == sign(a[j]) ):
            max_ = max(a[j],max_)
            j+=1
        ans += max_
        i = j-1
        i+=1
    print(ans)
