for _ in range(int(input())):
  x=int(input())
  num=list(map(int, input().split()))
  position=[]
  flag=0
  for i in range(x):
    if flag<=0 and num[i]<0:
      position.append(i)
      flag=1
    elif flag>=0 and num[i]>0:
      position.append(i)
      flag=-1
  sum=0
  for i in range(len(position)-1):
    sum+=max(num[position[i]:position[i+1]])
  sum+=max(num[position[-1]:])
  print(sum,)
