#take max value from each plus/minus cluster
t=int(input())
for _ in range(t):
    n=int(input())
    *a,=map(int, input().split( ))
    a2=[]
    tmp=[]
    for i in range(n):
        if tmp:
            if tmp[-1]*a[i]<0:
                a2.append(tmp)
                tmp=[a[i]]
            else:
                tmp.append(a[i])
        else:
            tmp.append(a[i])
    a2.append(tmp)
    ans=0
    for s in a2:
        ans+=max(s)
    print(ans)

