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