t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    flag = a[0] > 0
    b = [a[0]]
    ans = 0
    for i in range(1,n):
        if flag:
            if a[i] > 0:
                b.append(a[i])
            else:
                ans += max(b)
                b = [a[i]]
                flag = False
        else:
            if a[i] < 0:
                b.append(a[i])
            else:
                ans += max(b)
                b = [a[i]]
                flag = True
    else:
        ans += max(b)

    print(ans)

