from itertools import groupby
for _ in range(int(input())):
    l = int(input())
    s = [int(x) for x in input().split()]
    xg = groupby(s, key=lambda x:x > 0)
    sums = 0
    for _, g in xg:
        sums += max(list(g))
    print(sums)