t=int(input())
for i in range(t):
    n= int(input())
    l=[int(x) for x in input().split()]
    ans1 = 0
    ans2 = 0
    i=0
    while(i<n):
        if(l[i]>0):
            max1 = 0
            while(i<n and l[i]>0):
                max1 = max(max1,l[i])
                i+=1
            ans1+=max1
        elif(l[i]<0):
            max1 = -1000000001
            while(i<n and l[i]<0):
                max1 = max(l[i],max1)
                i+=1
            ans1+=max1
    i = 0
    while(i<n):
        if(l[i]<0):
            max1 = -1000000001
            while(i<n and l[i]<0):
                max1 = max(l[i],max1)
                i+=1
            ans2+=max1
        elif(l[i]>0):
            max1 = 0
            while(i<n and l[i]>0):
                max1 = max(max1,l[i])
                i+=1
            ans2+=max1
    print(max(ans1,ans2))