def solve(a, k, n):
    ans = 0
    i = 0
    while i < n:
        j = i
        if k == 0:
            max_pos = float("-inf")
            found = False
            while j < n and a[j] > 0:
                max_pos = max(max_pos, a[j])
                found = True
                j += 1
            k = (k+1) % 2
            if found:
                ans += max_pos
            i = j
            # print("Positive " + str(ans), end=" ")
        else:
            max_negative = float("-inf")
            found = False
            while j < n and a[j] < 0:
                max_negative = max(max_negative, a[j])
                found = True
                j += 1
            k = (k+1) % 2
            if found:
                ans += max_negative
            i = j
            # print("Negative " + str(ans), end=" ")
    return ans


t = int(input())
while t:
    t -= 1
    n = int(input())
    a = list(map(int, input().split()))
    if a[0] > 0:
        ans = solve(a, 0, n)
    else:
        ans = solve(a, 1, n)
    print(ans)
