import atexit
import io
import sys
import math
from collections import defaultdict

_INPUT_LINES = sys.stdin.read().splitlines()
raw_input = iter(_INPUT_LINES).next
_OUTPUT_BUFFER = io.BytesIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

t=int(raw_input())
for i in range(t):
    n=int(raw_input())
    a=list(map(int,raw_input().split()))
    if a[0]>0:
        flag=0
    else:
        flag=1
    s=0
    p=a[0]
    for j in range(1,n):
        #print s
        if flag==0:
            if a[j]>0:
                p=max(p,a[j])
            else:
                s+=p
                p=a[j]
                flag=1
        else:
            if a[j]<0:
                p=max(p,a[j])
            else:
                s+=p
                p=a[j]
                flag=0
    s+=p
    print s