"""
from collections import Counter

t=int(input())
for i in range(t):
    n = int(input())
    nums = list(map(int, input().split()))
    c = Counter(nums)
    ans = 0
    for i,j in c.items():
        ans += j//i
        c[i] = j%i
    print(c)
    print(ans)"""


"""
from functools import lru_cache

@lru_cache(maxsize=None)
def findMinMax(s):
    if len(s)==1:
        return int(s[0])**2
    return int(s[0])*int(s[-1])



t = int(input())
for i in range(t):
    a,k = list(map(int, input().split()))
    for i in range(k-1):
        l = "".join(sorted(str(a)))
        if "0" in l:
            break
        else:
            a += findMinMax(l)
    print(a)"""

t = int(input())
for i in range(t):
    n = int(input())
    nums = list(map(int, input().split()))
    nums = [[i] for i in nums]
    pos = 0
    while pos < len(nums)-1:
        if nums[pos] and nums[pos+1]:
            if (nums[pos][0] < 0 and nums[pos+1][0] < 0) or (nums[pos][0] > 0 and nums[pos+1][0] >0):
                nums[pos].append(nums[pos+1][0])
                nums[pos+1].pop(0)
        pos += 1

    ans = 0
    cur = max(nums[0])
    ans += cur
    for i in range(1, len(nums)):
        if nums[i]:
            if cur < 0 and max(nums[i]) > 0:
                cur = max(nums[i])
                ans += cur
            elif cur > 0 and max(nums[i]) < 0:
                cur = max(nums[i])
                ans += cur

    print(ans)








