###########{BHOLE KI FAUJ KREGI MAUJ}######## 
def isPrime(n) : 
    if (n <= 1) : 
        return False
    if (n <= 3) : 
        return True
    if (n % 2 == 0 or n % 3 == 0) : 
        return False
    i = 5
    while(i * i <= n) : 
        if (n % i == 0 or n % (i + 2) == 0) : 
            return False
        i = i + 6
    return True

from sys import stdin,stdout 
import math,queue,heapq
fastinput=stdin.readline
fastout=stdout.write
t=int(fastinput()) 

while t:
    t-=1 
    n=int(fastinput()) 
    a=list(map(int,fastinput().split())) 
    stack=[a[0]] 
    for i in a[1:]:
        if stack[-1]*i>0: 
            stack[-1]=max(stack[-1],i) 
        else:
            stack.append(i) 
    print(sum(stack))
    