def check(x, y):
    if (x > 0 and y > 0) or (x < 0 and y < 0):
        return True
    else:
        return False


for i in range(int(input())):
    n = int(input())
    arr = [int(i) for i in input().split()]
    summ = 0
    cnt = arr[0]
    for i in range(n-1):
        if arr[i] * arr[i+1] < 0:
            summ += cnt
            cnt = arr[i+1]
        else:
            if arr[i+1] > cnt:
                cnt = arr[i+1]
    print(summ + cnt)


