#include <bits/stdc++.h>
using namespace std;
const long long m = 1e9;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; ++i) cin >> a[i];
    vector<long long> v;
    for (long long i = 0; i < n; ++i) {
      if (a[i] > 0)
        v.emplace_back(a[i]);
      else {
        long long mx = -1e18;
        while (i < n && a[i] < 0) {
          mx = max(mx, a[i]);
          ++i;
        }
        v.emplace_back(mx);
        --i;
      }
    }
    long long sum = 0;
    for (long long i = 0; i < v.size(); ++i) {
      if (v[i] < 0)
        sum += v[i];
      else {
        long long mx = -1e18;
        while (i < v.size() && v[i] > 0) {
          mx = max(mx, v[i]);
          ++i;
        }
        sum += mx;
        --i;
      }
    }
    cout << sum << "\n";
  }
}
