#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000")
#pragma warning(disable : 6031)
#pragma warning(disable : 4244)
#pragma warning(disable : 26451)
#pragma GCC target("sse4.2")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const long long LINF = 1e18;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << setprecision(18) << fixed;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (auto& x : a) cin >> x;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      long long me = LLONG_MIN;
      auto sign = [](long long a) { return a < 0; };
      for (int j = i; j < n; j++) {
        if (sign(a[i]) == sign(a[j])) {
          cnt++;
          me = max(a[j], me);
        } else
          break;
      }
      sum += me;
      i += cnt - 1;
    }
    cout << sum << "\n";
  }
  return 0;
}
