import math
import sys
from collections import defaultdict
from collections import Counter
from collections import deque
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]

for _ in range(int(input())):
    N = int(input())
    A = alele()
    i = 0;B = [];temp = [];pos = -1
    while i<len(A):
        if len(temp) == 0:
            if A[i] < 0:
                pos = 0
                temp.append(A[i])
            else:
                pos = 1
                temp.append(A[i])
        else:
            if pos == 1:
                if A[i] > 0:
                    temp.append(A[i])
                else:
                    pos = 0
                    B.append(max(temp))
                    temp = []
                    temp.append(A[i])
            else:
                if A[i] < 0:
                    temp.append(A[i])
                else:
                    pos = 1
                    B.append(max(temp))
                    temp = []
                    temp.append(A[i])
        i+=1
    if len(temp) != 0:
        if temp[0]<0:
            B.append(max(temp))
        else:
            B.append(max(temp))
    #print(B)
    print(sum(B))
                
                