import sys

for i in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    msum = 0
    j = 0
    while j <= n - 1:
        mx = -sys.maxsize - 1
        if a[j] > 0:
            while j <= n - 1 and a[j] > 0:
                mx = max(mx, a[j])
                j += 1
        else:
            while j <= n - 1 and a[j] < 0:
                mx = max(mx, a[j])
                j += 1
        msum += mx
    print(msum)
