class Pair:
    def __init__(self, a, b):
        self.a = a
        self.b = b

    def __lt__(self, o):
        return self.b < o.b if self.a == o.a else self.a < o.a

    def add(self, c):
        return Pair(self.a + 1, self.b + c)


if __name__ == '__main__':
    cas = int(input())
    for _ in range(cas):
        n = int(input())
        r1 = Pair(0, 0)
        r2 = Pair(0, 0)
        x = [int(i) for i in input().split()]
        for xx in x:
            if xx > 0:
                r = r2.add(xx)
                if r1 < r:
                    r1 = r
            else:
                r = r1.add(xx)
                if r2 < r:
                    r2 = r
        print(r1.b if r2 < r1 else r2.b)


