from pprint import pprint
import sys
input = sys.stdin.readline

q = int(input())
for _ in range(q):
    n = int(input())
    dat = list(map(int, input().split()))
    res = -99999999999999999999999999999999999
    candidate = []
    buf = []
    isnega = True if dat[0] < 0 else False
    for i in range(n):
        if isnega:
            if dat[i] > 0:
                candidate.append(max(buf))
                buf = []
                isnega = False
            else:
                pass
        else: # posi
            if dat[i] < 0:
                candidate.append(max(buf))
                buf = []
                isnega = True
            else:
                pass
        buf.append(dat[i])
    candidate.append(max(buf))
    print(sum(candidate))
