import sys

t = int(sys.stdin.readline())
for _ in range(t):
    n = int(sys.stdin.readline())
    a = list(map(int, sys.stdin.readline().split()))
    idx = 0
    res = 0
    b = []

    if n == 1:
        print(a[0])
        continue

    for i in range(1, len(a)):
        if a[i] * a[i-1] < 0:
            b.append(a[idx:i])
            idx = i
        if i == n-1:
            b.append(a[idx:i+1])

    for i in range(len(b)):
        res += max(b[i])
        
    print(b)
    print(res)