import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

t = ni()
for i in range(t):
    n = ni()
    a = na()
    ans = 0
    t = a[0]
    for j in range(1, n):
        if a[j] * t > 0:
            t = max(a[j], t)
        else:
            ans += t
            t = a[j]
    ans += t
    print(ans)