for u in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    ka=0
    m=-1000000007
    i=0
    while(i<n):
        m=l[i]
        if(l[i]<0):
            while(i<n and l[i]<0):
                if(l[i]>m):
                    m=l[i]
                i=i+1
            ka=ka+m
            m=-1000000007
        else:
            while(i<n and l[i]>0):
                if(l[i]>m):
                    m=l[i]
                i=i+1
            ka=ka+m
            m=-1000000007
    print(ka)
