for _ in range(int(input())):
  n=int(input())
  a=list(map(int,input().split()))
  total=0
  m=a[0]
  for i in range(1,n):
    if (m>0 and a[i]<0)or(m<0 and a[i]>0):
      total+=m
      m=a[i]
    else:
      m=max(m,a[i])
  print(total+m)
