import sys
input = sys.stdin.readline

def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        A = tuple(map(int,input().split()))
        sgn = (A[0]>0)
        ans = [A[0]]
        for a in A:
            if sgn == (a>0):
                ans[-1] = max(ans[-1],a)
            else:
                ans.append(a)
                sgn = (a>0)
        print(sum(ans))
if __name__ == "__main__":
    main()