t = int(input())
for z in range(t):
    ans = []
    sign = -1
    ma = -1000000000000000000000
    n = int(input())
    a = list(map(int, input().split()))
    if a[0] < 0:
        sign = -1
    else:
        sign = 1
    ls = 0
    for i in a:
        ls = i
        if i * sign < 0:
            ans.append(ma)
            ma = -1000000000000000000000
            sign = -sign
        ma = max(ma, i)
    if ls * sign > 0:
        ans.append(ma)
    print(sum(ans))
        