def solution():
    from sys import stdout, stdin
    _input, _print = stdin.readline, stdout.write
    for _ in range(int(input())):
        n = int(input())
        arr = [int(i) for i in input().split()]
        flag = arr[0] > 0
        current = 0
        summary = 0
        for i, v in enumerate(arr):
            if flag:
                if v > 0:
                    if current:
                        if v > current:
                            current = v
                    else:
                        current = v
                else:
                    summary += current
                    current = v
                    flag = False
            else:
                if v < 0:
                    if current:
                        if v > current:
                            current = v
                    else:
                        current = v
                else:
                    summary += current
                    current = v
                    flag = True
        summary += current
        print(summary)
solution()
