#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int mod(int x, int m) {
  if (x < 0) x += m;
  return x % m;
}
bool sign(int x) { return x > 0; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int& i : v) cin >> i;
    long long ans = 0;
    bool c_sign = (v[0] > 0);
    for (int i = 0; i < n; ++i) {
      int mx = v[i];
      while (i < n && sign(v[i]) == c_sign) {
        mx = max(v[i], mx);
        i++;
      }
      if (i < n) c_sign = sign(v[i]);
      i--;
      ans += mx;
    }
    cout << ans << '\n';
  }
  return 0;
}
