t=int(input())
for _ in range(t):
  n=int(input())
  a=list(map(int,input().split()))
  s=0
  i=0
  while i<n:
    if a[i]>0:
      x=0
      while i<n and a[i]>0:
        x=max(x,a[i])
        i+=1
      s+=x
    else:
      x=-10**18
      while i<n and a[i]<0:
        x=max(x,a[i])
        i+=1
      s+=x
  print(s)