t = input()
t = int(t)
for i in range(t):
      n = input()
      n = int(n)
      a = [int(x) for x in input().split()]
      mp=0
      mn=-1e10
      ans=0
      for j in range(n):
           if a[j]<0:
               mn=max(mn,a[j])
               ans=ans+mp
               mp=0 
           else:
               mp=max(mp,a[j])
               if mn!=-1e10:
                   ans= ans+mn
               mn=-1e10
      ans=ans+mp
      if mn!=-1e10:
         ans=ans+mn
      print(ans)
       