from collections import defaultdict,deque
import heapq,bisect,math,itertools,string,queue,copy,time

import sys
# sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())

t = inp()
for _ in range(t):
    n = inp()
    a = inpl()
    ans = 0
    before_is_negative = a[0] > 0
    tmp=0
    for i in range(len(a)):
        if before_is_negative:
            if a[i] > 0:
                ans += tmp
                tmp = a[i]
            else:
                tmp = max(tmp, a[i])
        else:
            if a[i] < 0:
                ans += tmp
                tmp = a[i]
            else:
                tmp = max(tmp, a[i])
        before_is_negative=a[i] < 0
    print(ans+tmp)

'''
1
5
1 2 3 -1 -2
'''