from math import ceil

class Solution:
    def __init__(self):
        self.n = int(input())
        self.a = [int(x) for x in input().split()]

    def solve_and_print(self):
        i = sum = 0
        is_neg = self.a[0] < 0
        while i < self.n:
            val = self.a[i]
            if is_neg:
                while i < self.n and self.a[i] < 0:
                    val = max(val, self.a[i])
                    i += 1
                is_neg = False
            else:
                while i < self.n and self.a[i] > 0:
                    val = max(val, self.a[i])
                    i += 1
                is_neg = True
            sum += val
        print(sum)

if __name__ == "__main__":
    for _ in range(int(input())):
        Solution().solve_and_print()