#include <bits/stdc++.h>
using namespace std;
bool sgn(int a) {
  if (a < 0)
    return false;
  else
    return true;
}
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (long long i = 0; i < n; i += 1) {
    cin >> v[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int j = i;
    int cur = v[i];
    while (j < n && sgn(v[i]) == sgn(v[j])) {
      cur = max(cur, v[j]);
      ++j;
    }
    ans += cur;
    i = j - 1;
  }
  cout << ans << endl;
}
int main() {
  int i;
  long long t = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) solve();
  return 0;
}
