from sys import stdin

debug = False


def join(_s, _l):
    return _s.join(map(str, _l))


def read(_f=None):
    if _f == None:
        return stdin.readline().strip()
    return _f(stdin.readline().strip())


def readlist(_f=None):
    _l = stdin.readline().strip().split()
    if _f == None:
        return _l
    return map(_f, _l)


readint = lambda: read(int)
readints = lambda: readlist(int)
printval = lambda _r: print(_r, end=" ")
printline = lambda _s, _r: print(join(_s, _r), end="\n")


def solve():
    n = readint()
    a = list(readints())
    start_pos = 0
    start_neg = 0
    for num in a:
        if num > 0:
            if start_pos % 2 == 0:
                start_pos += 1
            if start_neg % 2 == 1:
                start_neg += 1
        else:
            if start_pos % 2 == 1:
                start_pos += 1
            if start_neg % 2 == 0:
                start_neg += 1

    # number of elements in the subsequence
    k = max(start_pos, start_neg)
    # start by taking positive ?
    positive = start_pos >= start_neg
    # now search k elements that sum the most
    max_sum = 0
    take_positive = positive
    max_value = float("-inf")
    for num in a:
        if take_positive:
            if num < 0:
                # add the max positive and start taking negatives
                max_sum += max_value
                max_value = num
                take_positive ^= 1
        else:
            if num > 0:
                max_sum += max_value
                max_value = num
                take_positive ^= 1

        max_value = max(max_value, num)

    max_sum += max_value
    return max_sum


if __name__ == "__main__":
    t = readint()
    for _ in range(t):
        if debug:
            print("-" * 20)
        if debug:
            print("ANS: ", end="")

        ans = solve()

        print(ans)
