#Template 1.0
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    t = INT()

    while(t!=0):
        n = INT()
        a = LIST()

        currmax = a[0]
        ans = []
        currSign = 0
        if(a[0]>0):
            currSign = 1

        for i in range(1, n):
            if(a[i]>0 and currSign==1):
                if(a[i] > currmax):
                    currmax = a[i]
            elif(a[i]>0 and currSign==0):
                currSign = 1
                ans.append(currmax)
                currmax = a[i]
            elif(a[i]<0 and currSign==1):
                currSign = 0
                ans.append(currmax)
                currmax = a[i]
            else:
                if(a[i]>currmax):
                    currmax = a[i]
        ans.append(currmax)
        print(sum(ans))
        t-=1

if __name__== "__main__":
    main()
