for i in range(int(input())):
    n,a=int(input()),list(map(int,input().split()))
    t,r,w=0+(a[0]>0),-10**12,a[0]
    for i in range(1,n):
        if a[i]>0and t==0:w+=a[i];t=1
        elif a[i]<0and t:w+=a[i];t=0
        else:r=max(r,w);w=a[i];t=0+(a[i]>0)
    print(max(r,w))