#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> v(n), ans;
  for (int i = 0; i < n; i++) cin >> v[i];
  int i = 0;
  while (i < n) {
    if (v[i] > 0) {
      int here = v[i];
      while (i < n && v[i] > 0) {
        here = max(here, v[i]);
        i++;
      }
      ans.push_back(here);
    }
    if (v[i] < 0) {
      int here = v[i];
      while (i < n && v[i] < 0) {
        here = max(here, v[i]);
        i++;
      }
      ans.push_back(here);
    }
  }
  long long p = 0;
  for (auto x : ans) p = p + x;
  cout << p << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
