w=int(input())
while(w>0):
    n=int(input())
    a=list(map(int,input().split()))
    s=0
    m=a[0]
    for i in range(n):
        if(m*a[i]>0):
            m=max(m,a[i])
        else:
            s=s+m
            m=a[i]
    print(s+m)




    w=w-1
