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

    for _ in range(1, t + 1):
        n = int(input())
        a = [int(i) for i in input().split(' ')]

        sol = 0

        i = 0
        while i < n:
            if a[i] > 0:
                max_i = 0
                while i < n and a[i] > 0:
                    max_i = max(a[i], max_i)
                    i += 1
            else:
                max_i = - 10**9 - 1
                while i < n and a[i] < 0:
                    max_i = max(a[i], max_i)
                    i += 1
            sol += max_i

        print(sol)


if __name__ == '__main__':
    main()
