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