T = int(input())
for case in range(T):
    N = int(input())
    data = list(map(int, input().split()))

    ans = 0
    maxs = data[0]

    if data[0] > 0:
        sign = 1
    else:
        sign = -1

    for elt in data:
        if elt > 0:
            nsign = 1
        else:
            nsign = -1
        if sign == nsign:
            maxs = max(maxs, elt)
        else:
            sign = nsign
            ans += maxs
            maxs = elt
    ans += maxs
    print(ans)
