#include <bits/stdc++.h>
using namespace std;
void Fast_IO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
int main() {
  Fast_IO();
  int n_testcases;
  cin >> n_testcases;
  for (int n_testcase = 1; n_testcase <= n_testcases; n_testcase++) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = (long long)0; i <= (long long)n - 1; i++) cin >> a[i];
    vector<long long> v;
    v.push_back(a[0]);
    for (long long i = (long long)1; i <= (long long)n - 1; i++) {
      if ((v[(long long)int(v.size()) - 1] < 0 && a[i] < 0) ||
          (v[(long long)int(v.size()) - 1] > 0 && a[i] > 0)) {
        v[(long long)int(v.size()) - 1] =
            max(v[(long long)int(v.size()) - 1], a[i]);
      } else {
        v.push_back(a[i]);
      }
    }
    long long ans = 0;
    for (auto x : v) ans += x;
    cout << ans << '\n';
  }
  return 0;
}
