for _ in range(int(input())):
    n = int(input())
    l = list(map(int, input().split()))
    if(l[0]>0):
        max = l[0]
        min = -(10**9+1)
        total = 0
        i=1
        while(i<n):
            while(i<n and l[i]>0):
                if(l[i]>max):
                    max = l[i]
                i+=1
            total+=max
            max = 0
            while(i<n and l[i]<0):
                if(l[i]>min):
                    min = l[i]
                i+=1
            total+=min
            min = -(10**9+1)
        print(total)
    else:
        min = l[0]
        max = 0
        total = 0
        i = 1
        while(i<n):
            while(i<n and l[i]<0):
                if(l[i]>min):
                    min = l[i]
                i+=1
            total+=min
            min = -(10**9+1)
            while(i<n and l[i]>0):
                if(l[i]>max):
                    max = l[i]
                i+=1
            total+=max
            max = 0
        print(total)