import sys
import collections
import threading


def main():
    n = int(input() )
    a = list(map(int, input().split()))
    ans = 0
    previsNeg = (a[0] < 0)
    previsPos = (a[0] > 0)
    acc = a[0]
    for c in a:
        if c > 0:
            if previsPos:
                acc = max(acc, c)
            else:
                ans += acc
                previsNeg = False
                previsPos = True
                acc = c
            continue
        else:
            if previsNeg:
                acc = max(acc, c)
            else:
                ans += acc
                previsNeg = True
                previsPos = False
                acc = c
    ans += acc
    print(ans)


input = sys.stdin.readline
#sys.setrecursionlimit(2097152)
tnum = int(input())
for _ in range(tnum):
    main()