from itertools import groupby


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


POSITIVE, NEGATIVE = 0, 1


def get_key(a):
    return POSITIVE if a > 0 else NEGATIVE


def solve():
    n = read_int()
    arr = read_ints()
    S = 0
    for _, numbers in groupby(arr, key=get_key):
        S += max(numbers)
    return S


if __name__ == '__main__':
    T = read_int()
    for _ in range(T):
        print(solve())
