#include <bits/stdc++.h>
bool signbit(int64_t v) { return v < 0; }
void work(std::ostream& os, std::istream& is) {
  size_t n = 0;
  is >> n;
  int64_t minV = (std::numeric_limits<int64_t>::min)();
  int64_t maxV = 0;
  int64_t v = 0;
  is >> v;
  bool prevSig = signbit(v);
  if (prevSig) {
    minV = std::max(v, minV);
  } else {
    maxV = std::max(v, maxV);
  }
  int64_t sum = 0;
  while (--n) {
    is >> v;
    if (signbit(v)) {
      minV = std::max(v, minV);
      if (!prevSig) {
        sum += maxV;
        maxV = 0;
      }
    } else {
      maxV = std::max(v, maxV);
      if (prevSig) {
        sum += minV;
        minV = (std::numeric_limits<int64_t>::min)();
      }
    }
    prevSig = signbit(v);
  }
  if (signbit(v)) {
    sum += minV;
  } else {
    sum += maxV;
  }
  os << sum << std::endl;
}
int main() {
  size_t t = 0;
  std::cin >> t;
  for (size_t i = 0; i < t; ++i) {
    work(std::cout, std::cin);
  }
  return 0;
}
