n = int(input())
for _ in range(n):
    x = int(input())
    l = list(map(int, input().split()))
    a = l[0]
    s = 0
    for i in range(x):
        if l[i]*a<0:
            s += a
            a = l[i]
        else:
            a = max(a, l[i])
    print(s+a)
