'''
inputCopy
4
5
1 2 3 -1 -2
4
-1 -2 -1 -3
10
-2 8 3 8 -4 -15 5 -2 -3 1
6
1 -1000000000 1 -1000000000 1 -1000000000
outputCopy
2
-1
6
-2999999997
'''
t = int(input())
for i in range(t):
    n = input()
    nums = input()
    nums = list(map(int, nums.split()))
    sums = 0
    flag = 0
    last = 0
    for now in nums:
        if now > 0:
            if flag > 0:
                if now > last:
                    last = now
            else:
                flag = 1
                sums += last
                last = now
        else:
            if flag < 0:
                if now > last:
                    last = now
            else:
                flag = -1
                sums += last
                last = now
    sums += last
    print(sums)

