#872
t=int(input())
for _ in range(t):
  n=int(input())
  a=[int(x)for x in input().split()]
  m=a[0]
  ss=0 
  for j in range(1,n):
    if(a[j]>0 and a[j-1]>0)or(a[j]<0 and a[j-1]<0):
      m=max(m,a[j])
    else:
      ss+=m
      m=a[j]
  ss+=m
  print(ss)