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