# coding=utf-8
# Author: lee215
# Date: 2020-04-22 22:49

get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]



def solve(N, A):
    res = 0
    cur = []
    for a in A:
        if cur and abs(cur[-1] + a) != abs(cur[-1]) + abs(a):
            res += max(cur)
            cur = []
        cur.append(a)
    res += max(cur)
    return res


def solve(N, A):
    res = 0
    i = 0
    for j, a in enumerate(A):
        if abs(A[i] + A[j]) != abs(A[i]) + abs(A[j]):
            res += max(A[i:j])
            i = j
    res += max(A[i:])
    return res


T = get()
for _ in xrange(T):
    N = get()
    A = gets()
    res = solve(N, A)
    print res
