import sys
import math
t = int(sys.stdin.readline())
while t:
    n = int(sys.stdin.readline())
    arr = list(map(int,sys.stdin.readline().split()))
    posnum = 0
    negnum = -math.inf
    ans = 0
    findpos = True
    findneg = True
    prev = ''
    for i in range(n):
        if arr[i]>0:
            if prev=='neg':
                ans+=negnum
                negnum = -math.inf
            if arr[i]>posnum:
                posnum= arr[i]
            prev = 'pos'
        elif arr[i]<0:
            if prev=='pos':
                ans+=posnum
                posnum = 0
            if arr[i]>negnum:
                negnum = arr[i]
            prev = 'neg'
    if prev=='neg':
        ans+=negnum
    else:
        ans+=posnum
    print(ans)

    t-=1