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