from sys import stdin
from collections import deque
mod = 10**9 + 7
import sys
import random
# sys.setrecursionlimit(10**6)
from queue import PriorityQueue
# def rl():
#     return [int(w) for w in stdin.readline().split()]
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt,factorial,gcd,log2,inf,ceil
# map(int,input().split())
# # l = list(map(int,input().split()))
# from itertools import permutations
import heapq
# input = lambda: sys.stdin.readline().rstrip()
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

# def ncr(x, y):
#     return f(x) // (f(y) * f(x - y))
def ncr(n, r, p):
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
                      p - 2, p)) % p

t = int(input())

for _ in range(t):

    n = int(input())
    l = list(map(int,input().split()))


    i = 0
    z = -10**18
    ans = 0
    while i<n:


        if l[i]>0:
            maxi = 0
            while l[i]>0:
                maxi = max(maxi,l[i])
                i+=1

                if i == n:
                    break

            ans+=maxi


        if i>=n:
            break
        if l[i]<0:
            maxi = z
            while l[i]<0:
                maxi = max(l[i],maxi)
                i+=1
                if i == n:
                    break

            ans+=maxi


    print(ans)


