t = int(input())
for i in range(t):
  n = int(input())
  l = list(map(int,input().split()))
  l.append(0)
  p = l[0]
  sm = 0
  for j in range(1,n+1):
    if (l[j]>= 0 and p<0) or  (l[j]<=0 and p>0):
      sm+=p
      p = l[j]
    elif l[j]>p:
      p = l[j]
  print(sm)

