def main():
    t = int(input())

    while t != 0:
        n = int(input())

        arr = [int(x) for x in input().split()]

        start = True
        ptr = 0
        currArr = []
        ans = 0
        smol = 0

        while ptr < n:
            if start:
                smol = arr[ptr]
                currArr.append(smol)
                start = False
            else:
                if arr[ptr] * smol > 0:
                    currArr.append(arr[ptr])
                else:
                    ans += max(currArr)
                    ptr -= 1
                    start = True
                    currArr = []

            ptr += 1
        
        ans += max(currArr)
        print(ans)

        t-= 1
                



if __name__ == "__main__":
    main()