from sys import stdin, gettrace

MIN = int(-1E10)

if not gettrace():
    def input():
        return next(stdin)[:-1]


# def input():
#    return stdin.buffer.readline()

def main():
    def solve():

        n = int(input())
        aa = [int(a) for a in input().split()]
        sum = 0
        mxp = 0
        mxn = MIN
        for a in aa:
            if a > 0:
                mxp = max(mxp, a)
                if mxn != MIN:
                    sum += mxn
                mxn = MIN
            else:
                mxn = max(mxn, a)
                sum += mxp
                mxp = 0
        sum += mxp + (0 if mxn == MIN else mxn)
        print(sum)


    q = int(input())
    for _ in range(q):
        solve()


if __name__ == "__main__":
    main()