#include <bits/stdc++.h>
const int INF = 1 << 29;
using namespace std;
void solve() {
  long long int n, ans = 0, mx = 0;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool ok = true;
  if (a[0] > 0)
    ok = true;
  else
    ok = false;
  for (int i = 0; i < n;) {
    if (ok == true) {
      mx = 0;
      while (i < n && a[i] > 0) {
        mx = max(a[i], mx);
        i++;
      }
      ans += mx;
      ok = false;
    } else {
      mx = -1e9;
      while (i < n && a[i] < 0) {
        mx = max(a[i], mx);
        i++;
      }
      ans += mx;
      ok = true;
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(10);
  cout << fixed;
  int t = 1;
  cin >> t;
  for (int ha = 1; ha <= t; ha++) {
    solve();
  }
  return 0;
}
