import math
from functools import lru_cache
import itertools

T = int(input())

for t in range(T):
    N = int(input())
    a = list(map(int, input().split()))

    s = 0

    for sign, g in itertools.groupby(a, key=lambda x: x > 0):
        s += max(g)

    print(s)
