#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
template <typename T, typename A>
int arg_max(std::vector<T, A> const& vec) {
  return static_cast<int>(
      std::distance(vec.begin(), max_element(vec.begin(), vec.end())));
}
template <typename T, typename A>
int arg_min(std::vector<T, A> const& vec) {
  return static_cast<int>(
      std::distance(vec.begin(), min_element(vec.begin(), vec.end())));
}
vector<int> binary2(ll x) {
  vector<int> res;
  while (x > 0) {
    res.push_back(x % 2);
    x >>= 1;
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll tt = 1;
  cin >> tt;
  for (ll tti = 0; tti < tt; ++tti) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) {
      cin >> a[i];
    }
    ll res = 0;
    int i = 0;
    while (i < n) {
      int j = i;
      ll maxi = a[i];
      while (j < n && (a[i] < 0 && a[j] < 0) || (a[i] > 0 && a[j] > 0)) {
        maxi = max(maxi, a[j]);
        ++j;
      }
      res += maxi;
      i = j;
    }
    cout << res << "\n";
  }
  return 0;
}
