'''
import sys
import math
import bisect
n=int(input())
arr=list(map(int,input().split()))
n,m=map(int,input().split())
t=sys.stdin.buffer.readline()
sys.stdin=open("input.txt")
sys.stdout=open("output.txt", 'w')
sys.stdout.write("Yes" + '\n')
s="abcdefghijklmnopqrstuvwxyz"
mod=1000000007
mod=998244353
vow=['a','e','i','o','u']
t=[[0 for i in range(n)]for j in range(n)]
pow(4,7)
def gcd(x,y):
    while y:
        x,y=y%x,x
    return y'''
for _ in range(int(input())):
    n=int(input())
    arr = list(map(int, input().split()))
    if arr[0]<0:
        flag=1
    else:
        flag=0
    i=1
    ind=0
    ls=[]
    while i<n:
        if arr[i]<0 and flag==0:
            m=max(arr[ind:i])
            ls.append(m)
            flag=1
            ind=i
            if i==n-1:
                ls.append(arr[n-1])
        elif arr[i]>0 and flag==1:
            flag=0
            ls.append(max(arr[ind:i]))
            ind=i
            if i==n-1:
                ls.append(arr[n-1])
        elif i==n-1:
            #if flag==0:
            ls.append(max(arr[ind:]))

            #else:
                #ls.append(min(arr[ind:]))
                #print("^")
        i+=1
    #print(ls)
    print(sum(ls))



