import math
import sys
input = sys.stdin.readline

def solve(n, arr):
    seg = -math.inf
    neg = arr[0] < 0
    total = 0
    for a in arr:
        if a < 0 and neg:
            seg = max(seg, a)
        elif a > 0 and not neg:
            seg = max(seg, a)
        else:
            if (a < 0 and not neg) or (a > 0 and neg):
                total += seg
                seg = a
        neg = a < 0
    return total + seg

if __name__ == "__main__":
    t = int(input())
    for i in range(t):
        n = int(input())
        arr = list(map(int,input().split()))
        print(solve(n, arr)) 