from sys import stdin
import math

def inp():
	return stdin.readline().strip()

t = int(inp())
for _ in range(t):
    n = int(inp())
    ar = [int(x) for x in inp().split()]
    ans1 = []
    pos = 0
    neg = float("-inf")
    posFlag = False
    negFlag = False
    for i in range(n):
        if ar[i] > 0:
            posFlag = True
            if negFlag:
                ans1.append(neg)
                neg = float("-inf")
                negFlag = False
            pos = max(pos, ar[i])
        elif ar[i] < 0:
            negFlag = True
            if posFlag:
                ans1.append(pos)
                pos = 0
                posFlag = False
            neg = max(neg, ar[i])
    if neg != float("-inf"):
        ans1.append(neg)
        neg = float("-inf")
    elif pos != 0:
        ans1.append(pos)
        pos = 0
    print(sum(ans1))