t = int(input())
for _ in range(t):
  n = int(input())
  a = list(map(int, input().split()))
  res = [a[0]]
  for i in range(1,n):
    if res[-1] > 0 and a[i] < 0:
      res.append(a[i])
    elif res[-1] < 0 and a[i] > 0:
      res.append(a[i])

    if res[-1] > 0 and a[i] > 0:
      res[-1] = max(res[-1], a[i])
    
    if res[-1] < 0 and a[i] < 0:
      res[-1] = max(res[-1], a[i])
  
  print(sum(res))