from math import copysign


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    i = 0
    ans = 0
    while i < n:
        now = a[i]
        i += 1
        while i < n and copysign(1, a[i-1]) == copysign(1, a[i]):
            now = max(now, a[i], a[i-1])
            i += 1
        ans += now
    print(ans)