#include <bits/stdc++.h>
using namespace std;
inline void io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
}
int main() {
  io();
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
      long long mx = -1;
      if (v[i] > 0 && i < n) {
        while (v[i] > 0 && i < n) mx = max(mx, v[i++]);
        --i;
        sum += mx;
      } else {
        mx = -1e18;
        while (v[i] < 0 && i < n) mx = max(mx, v[i++]);
        --i;
        sum += mx;
      }
    }
    cout << sum << '\n';
  }
  return 0;
}
