def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        nums = list(map(int, input().split()))
        sign = 1 if nums[0] > 0 else -1
        cur_max = float('-inf')
        ans = 0
        for x in nums:
            if x * sign > 0:
                cur_max = max(cur_max, x)
            else:
                ans += cur_max
                cur_max = x
                sign = -sign
        ans += cur_max
        print(ans)


if __name__ == "__main__":
    main()