import sys


class l(list):

    def __init__(self, type):
        self.type = type  # -1 for neg 1 for pos

    def push(self, x):

        if not len(self):
            if ~self.type and x >= 0:
                self.append(x)
            elif not ~self.type and x < 0:
                self.append(x)
            return

        t = self[-1]

        if t < 0:
            if 0 > x > t:
                self[-1] = x
            elif x >= 0:
                self.append(x)
        else:
            if x > t > 0:
                self[-1] = x
            elif x < 0:
                self.append(x)


def main():
    ans = ""

    for _ in range(int(input())):
        n = int(input())
        x = [int(i) for i in input().split()]
        neg_first = l(-1)
        pos_first = l(1)

        for xi in x:
            neg_first.push(xi)
            pos_first.push(xi)

        m = max(len(neg_first), len(pos_first))
        
        if m == len(neg_first):
            c_ans = sum(neg_first)
        else:
            c_ans = sum(pos_first)
        ans += f"{c_ans}\n"

    sys.stdout.write(ans)
main()
