
def solve():
    n = int(input())
    arr = list(map(int, input().split(' ')))
    temp = [arr[0]]

    sign = 1 if temp[0] > 0 else -1
    maxArr = []
    for i in range(1,n):
        if sign * arr[i] < 0:
            sign *= -1
            maxArr.append(max(temp))
            temp = []
        temp.append(arr[i])
    if len(temp) > 0:
        maxArr.append(max(temp))

    print(sum(maxArr))
if __name__ == "__main__":
    t = int(input())
    for i in range(t):
        solve()