t=int(input())
for _ in range(t):
  n=int(input())
  a=list(map(int,input().split()))
  s=[0]
  for i in range(n-1):
    if a[i]*a[i+1]<0:
      s.append(i+1)
  s.append(n)
  b=list()
  c=0
  if a[0]>0:
    c=1
  for i in range(len(s)-1):
    if c==0:
      b.append(max(a[s[i]:s[i+1]]))
    else:
      b.append(max(a[s[i]:s[i+1]]))
    c=1-c
  print(sum(b))