T = int(input())

for t in range(T):
    n = int(input())
    a = list(map(int, input().split()))

    ans = i = 0

    while i < n:
        if a[i] > 0:
            maxv = -10**9
            while  i < n and a[i] > 0:
                maxv = max(maxv, a[i])
                i += 1

            ans += maxv
        else:
            maxv = -10**9
            while i < n and  a[i] < 0 :
                maxv = max(maxv, a[i])
                i += 1
            ans += maxv
    print(ans)
