def sol(l, n):
    m = 0
    cm = l[0]
    prev = 0 if cm < 0 else 1
    for i in range(1, n):
        if l[i] < 0:
            if not prev:
                cm = max(l[i], cm)
            else:
                m += cm
                cm = l[i]
                prev = 0
        else:
            if prev:
                cm = max(cm, l[i])
            else:
                m += cm
                cm = l[i]
                prev = 1
    return m+cm



t = int(input())
for _ in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(l, n))
