def sign(n):
    if abs(n) == n:
        return True
    return False

def func(arr):
    sum = 0
    last_added = arr[0]
    sum = arr[0]
    for el in arr[1:]:
        if sign(el) == sign(last_added) and el > last_added:
            sum = sum - last_added + el
            last_added = el
        elif sign(el) != sign(last_added):
            sum += el
            last_added = el
    print(sum)


data = []
n = int(input())
for _ in range(n):
    _ = input()
    data.append(list(map(int, input().split(' '))))
        
for d in data:
    func(d)