def AlternatingSubsequence(n,A):
    vis=[0]*n
    for i in range(n):
        if A[i]>0:
            vis[i]=1
    i=0
    sum=0
    while(i<n):
        M=A[i]
        j=i+1
        while(j<n and vis[i]==vis[j]):
            M=max(M,A[j])
            j+=1
        sum+=M
        i=j
    return sum

L=[]
t=int(input())
for i in range(t):
    n=int(input())
    A=[int(x) for x in input().split()]
    L.append(AlternatingSubsequence(n,A))

for l in L:
    print(l)