for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    if(n==0 or n==1):
        print(sum(a))
    else:
        seo=0
        pup=0
        nek=-1000000000
        fp=0
        fn=0;hjsd=0;bdjs=8;sui=0;klo=9
        for i in range(n):
            sui+=1
            if(a[i]<0):
                if(fn==1):
                    nek=max(nek,a[i])
                else:
                    nek=a[i]
                fn=1
                if(fp==1):
                    seo+=pup
                fp=0
            else:
                klo+=1
                if(fp==1):
                    pup=max(pup,a[i])
                else:
                    pup=a[i]
                fp=1
                if(fn==1):
                    seo+=nek
                fn=0
        if(a[n-1]<0):
            seo+=nek
        else:
            seo+=pup
        hjsd+=1
        print(seo)