'''
22nd april 2020 wednesday
13343 Problem C
'''


def negative_picker(a):
    N = len(a)

    xsum, i, xlen = 0, 0, 0

    while i < N and a[i] > 0:
        i += 1

    while i < N:
        nmax = a[i]
        while i < N and a[i] < 0:
            nmax = max(nmax, a[i])
            i += 1
        xsum += nmax
        xlen += 1

        if i >= N:
            break

        pmax = a[i]
        while i < N and a[i] > 0:
            pmax = max(pmax, a[i])
            i += 1
        xsum += pmax
        xlen += 1

    return (xsum, xlen)


def postive_picker(a):
    N = len(a)

    xsum, i, xlen = 0, 0, 0

    while i < N and a[i] < 0:
        i += 1

    while i < N:
        pmax = a[i]
        while i < N and a[i] > 0:
            pmax = max(pmax, a[i])
            i += 1
        xsum += pmax
        xlen += 1

        if i >= N:
            break

        nmax = a[i]
        while i < N and a[i] < 0:
            nmax = max(nmax, a[i])
            i += 1
        xsum += nmax
        xlen += 1

    return (xsum, xlen)


for _ in range(int(input())):
    N = int(input())
    a = list(map(int, input().split()))

    lo, hi = 0, N - 1
    psum, nsum = postive_picker(a), negative_picker(a)
    out = max(psum, nsum, key=lambda x: x[1])
    print(out[0])

