t=int(input())
for x in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    i=0
    max_sum=0

    while i<len(a):
        temp_max=a[i]
        i+=1
        if(i<len(a)):
            if(a[i-1]>0):

                while i<len(a) and  a[i]>0:
                    if(a[i]>temp_max):
                        temp_max=a[i]
                    i+=1
            else:
                while i<len(a) and a[i]<0:

                    if(a[i]>temp_max):
                        temp_max=a[i]
                    i+=1
        max_sum+=temp_max

    print(max_sum)
            
