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

    ans = [a[0]]
    for i in range(n):
        if ans[-1] > 0:
            if a[i] > 0 and a[i] > ans[-1]:
                ans[-1] = a[i]
            elif a[i] < 0:
                ans.append(a[i])
        else:
            if a[i] < 0 and a[i] > ans[-1]:
                ans[-1] = a[i]
            elif a[i] > 0:
                ans.append(a[i])

    print(sum(ans))

