for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    currArr = [a[0]]
    b = []
    for i in range(1, n):
        if currArr[0] > 0 and a[i] > 0:
            currArr.append(a[i])
        elif currArr[0] < 0 and a[i] < 0:
            currArr.append(a[i])
        else:
            b.append(max(currArr))
            currArr = [a[i]]
        if i == n - 1:
            b.append(max(currArr))


    print(sum(b))


