from collections import Counter, defaultdict
from heapq import heappush, heappop, heapify
import math
from functools import reduce
import sys

def all_factors(n):
    return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))


t = int(input())
for _ in range(t):
    n = int(input())
    ls = list(map(int,input().strip().split()))
    search = True
    choose = ls[0]
    if ls[0]<0:
        search = False
    ans = 0
    for val in ls[1:]:
        #print(val,ans)
        if search:
            if val>0:
                choose = max(choose,val)
            else:
                ans += choose
                choose = val
                search = not search
        else:
            if val<0:
                choose = max(choose,val)
            else:
                ans += choose
                choose = val
                search = not search

    # if choose!=0 and choose!=(-sys.maxsize-1):
    ans += choose
    print(ans)
