#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 21 21:11:52 2020

@author: akash
"""

t = int(input())
for case in range(t) :
    n = int(input())
    a = list(map(int, input().split()))
    maxlen = 0
    maxSum = 0
    curr = 0
    if a[0] > 0 :
        maxlen += 1
        curr = a[0]
        status = 1
    else:
        maxlen += 1
        curr = a[0]
        status = 0
    for i in range(1, n) :
        if status == 1 :
            if a[i] < 0:
                maxlen += 1
                status = 0
                maxSum += curr
                curr = a[i]
            else :
                curr = max(a[i], curr)
        if status == 0 :
            if a[i] > 0 :
                maxlen += 1
                status = 1
                maxSum += curr
                curr = a[i]
            else :
                curr = max(a[i], curr)
        if i == n-1:
            maxSum += curr
    print(maxSum)
    
    
# =============================================================================
#     if maxlen1 == 0 :
#         print(a_copy[-1])
#     elif maxlen2 == 0:
#         print(a_copy[-1])
#     else :
#         maxlen = min(maxlen1, maxlen2)
#         Sum1 = 0
#         for i in range(maxlen) :
#             Sum1 += a_copy[i]
#         print(Sum1)
#         Sum2 = 0
#         for i in range(n-1, n-maxlen-1, -1) :
#             Sum2 += a_copy[i]
#         print(Sum2)
#         print(Sum1 + Sum2)
# =============================================================================
