def compute(n, arr):
    stack = [arr[0]]
    cur_sum = arr[0]
    for i in range(1, n):
        if (stack[-1] > 0 and arr[i] > 0) or (stack[-1] < 0 and arr[i] < 0):
            if arr[i] > stack[-1]:
                cur_sum -= stack[-1]
                cur_sum += arr[i]
                stack[-1] = arr[i]
        else:
            stack.append(arr[i])
            cur_sum += arr[i]
    return cur_sum
                

        

if __name__ == "__main__":
    t = int(input())
    for _ in range(t):
        n = int(input())
        arr = list(map(int, input().split()))
        print(compute(n, arr))
