t = int(input())
inf = -10**10
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    plus = (a[0] > 0)
    m = a[0]
    ans = 0
    for i in range(1, n):
        if plus and a[i] < 0:
            ans += m
            plus = False
            m = inf
        elif not plus and a[i] > 0:
            ans += m
            plus = True
            m = inf
        m = max(a[i], m)
    print(ans + m)
