T = int(input())
for t in range(T):
  n = int(input())
  l = list(map(int,input().split()))
  s=0
  k=l[0]
  last=l[0]
  for i in range(1,len(l)):
    if last*l[i]<0:
      s+=k
      k=l[i]
    else:
      if l[i]>k:
        k=l[i]
    last=l[i]
  s+=k

  print(s)
    
