for t in range(int(input().strip())):
    n = int(input().strip())
    arr = tuple(map(int, input().strip().split()))
    pv = arr[0]
    res = 0
    for i in range(1,n):
        if pv * arr[i] < 0:
            res += pv
            pv = arr[i]
        else:
            pv = max(pv, arr[i])
    res += pv
    print(res)
