def read_nums():
    return [int(x) for x in input().split()]


def sign(num):
    return 1 if num > 0 else -1


def split_patches(nums):
    cur_patch = []
    for num in nums:
        if len(cur_patch) == 0 or sign(cur_patch[-1]) == sign(num):
            cur_patch.append(num)
        else:
            yield cur_patch
            cur_patch = [num]
    if len(cur_patch) > 0:
        yield cur_patch


def main():
    for _ in range(int(input())):
        _ = read_nums()
        nums = read_nums()
        print(sum(map(max, split_patches(nums))))


if __name__ == '__main__':
    main()
