for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    f=True
    s1=0
    inf=float("inf")
    M1=-inf
    for i in a:
        if f and i>0:
            M1=max(M1,i)
        elif f and i<0:
            s1+=M1
            M1=i
            f=False
        elif not f and i<0:
            M1=max(M1,i)
        elif not f and i>0:
            s1+=M1
            M1=i
            f=True
            
    s1+=M1
    f=False
    s2=0
    inf=float("inf")
    M2=-inf
    for i in a:
        if f and i>0:
            M2=max(M2,i)
        elif f and i<0:
            s2+=M1
            M2=i
            f=False
        elif not f and i<0:
            M2=max(M2,i)
        elif not f and i>0:
            s2+=M2
            M2=i
            f=True
            
    s2+=M2
    print(max(s1,s2))
