import heapq
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    i = 0
    while i < n:
        if a[i] < 0:
            mx_val = float("-inf")
            while i < n and a[i] < 0:
                mx_val = max(mx_val, a[i])
                i+=1
            ans += mx_val
        else:
            mx_val = float("-inf")
            while i < n and a[i] > 0:
                mx_val = max(mx_val, a[i])
                i += 1
            ans += mx_val
    print(ans)