def R(): return map(int, input().split())
def I(): return int(input())
def S(): return str(input())

def L(): return list(R())

from collections import Counter 

import math
import sys

from itertools import permutations

import bisect

def sign(x):
    return math.copysign(1,x)

for _ in range(I()):

    n=I()
    a=L()
    s=sign(a[0])
    ss=set()

    ans=0
    cnt=1

    for i in range(n+1):
        if i==n or sign(a[i])!=s:
            s*=-1
            ans+=max(ss)
            ss.clear()
            cnt+=1

        if i==n:
            break

        ss.add(a[i])

    print(ans)
