if __name__== "__main__":
    t = int(input())
    for _ in range(t):
        input()
        a = list(map(int, input().split()))
        pos = a[0] > 0
        result = 0
        cur_max = a[0]
        for aa in a:
            if pos == (aa > 0):
                if aa > cur_max:
                    cur_max = aa
            else:
                pos = not pos
                result += cur_max
                cur_max = aa
        result += cur_max
        print(result)

