for i in range(int(input())):
  n=int(input())
  arr=[int(i) for i in input().split()]
  sign=arr[0]
  m,s=arr[0],0
  na=[]
  for i in range(n):
    if sign*arr[i]>0:
      m=max(m,arr[i])
    else:
      s+=m
      na.append(m)
      m,sign=arr[i],arr[i]
  print(s+m)
      
