def sign(a,b):
    if abs(a) == a and abs(b) == b:
        return 0
    elif abs(a) != a and abs(b) != b:
        return 0
    else:
        return 1

t = int(input())
for _ in range(t):
    n = int(input())
    items = list(map(int,input().split()))

    res = 0
    m = [items[0]]

    for i in range(1,n):
        if sign(items[i],items[i-1]) == 0:
            m.append(items[i])
        else:
            res += max(m)
            m = [items[i]]
    res += max(m)
    print(res)