from math import *
from bisect import bisect_left, bisect_right
from queue import Queue
from sys import stdin, stdout
from collections import Counter
input = lambda: stdin.readline().strip()
print = stdout.write
 
t = int(input())
for _ in range(t):
    n = int(input())
    ls = list(map(int, input().split()))
    M = ls[0]
    s = 0
    flag = 0 if ls[0]>0 else 1
    for i in range(n):
        if (ls[i]>0 and flag==0) or (ls[i]<0 and flag==1):
            M = max(M, ls[i])
        else:
            s+=M
            M = ls[i]
            flag = 1-flag
    s+=M
    print(str(s)+'\n')
