from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
out=sys.stdout.write
#sys.setrecursionlimit(100000)

for i in range(int(data())):
    n=int(data())
    A=list(mdata())
    d1=0
    s1=0
    d2=0
    s2=0
    ind=0
    for i in range(n):
        if A[i]>0:
            ind=i
            break
    s2+=A[ind]
    t=A[ind]
    d2+=1
    for i in range(ind+1, n):
        if (A[i] > 0 and A[i - 1] > 0) or (A[i] < 0 and A[i - 1] < 0):
            s2 -= t
            t=max(t,A[i])
            s2 += t
        else:
            d2 += 1
            s2 += A[i]
            t=A[i]
    ind=0
    for i in range(n):
        if A[i] < 0:
            ind = i
            break
    s1+=A[ind]
    t=A[ind]
    d1+=1
    for i in range(ind+1, n):
        if (A[i] > 0 and A[i - 1] > 0) or (A[i] < 0 and A[i - 1] < 0):
            s1 -= t
            t = max(t, A[i])
            s1 += t
        else:
            d1 += 1
            s1 += A[i]
            t = A[i]


    if d1==d2:
        print(max(s1,s2))
    elif d1>d2:
        print(s1)
    else:
        print(s2)

