for _ in range(int(input())):
    N = int(input())
    arr = [int(x) for x in input().split()]
    ans = arr.pop(0)

    last = ans
    is_positive = last > 0

    for n in arr:
        if (n > 0) != is_positive:
            is_positive = not is_positive
            ans += n

        elif n > last:
            ans += n - last

        else:
            continue

        last = n

    print(ans)
