t = input()
while t > 0:
    t -= 1
    n = input()
    a = map(int, raw_input().split())
    sum = 0
    last = a[0]
    accepted = 0
    ans = 0
    for i in range(1, n):
        curr = a[i]
        if ans == 0:
            if last > 0:
                if curr > 0:
                    last = max(last, curr)
                else:
                    # print last
                    accepted += last
                    last = curr
            else:
                if curr < 0:
                    last = max(last, curr)
                else:
                    # print last
                    accepted += last
                    last = curr
    min_ = a[n-1]
    for i in range(n-2, -1, -1):
        curr = a[i]
        if min_ * curr < 0:
            break
        else:
            min_ = max(min_, curr)

    print accepted + min_
