import math
N = int(input())

for i in range(N):
    n = int(input())
    a = list(map(int,input().strip().split(" ")))
    sum = 0
    prev =None
    for x in a:
        if prev is None:
            prev = x
            continue
        else:
            if prev<0 and x>0:
                sum+=prev
                prev = x
            elif prev>0 and x<0:
                sum+=prev
                prev = x
            else:
                if x>prev:
                    prev=x

    print(sum+prev)
