#include <bits/stdc++.h>
using namespace std;
void start() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
mt19937_64 rnd(time(0));
signed main() {
  start();
  long long t;
  cin >> t;
  while (t--) {
    long long n, s = 0, m = -1e9 - 9, c = 1, l = 0;
    cin >> n;
    vector<long long> a(n), b;
    for (long long i = 0; i < n; ++i) cin >> a[i];
    if (a[0] < 0) c = -1;
    m = a[0];
    for (long long i = 0; i < n; ++i) {
      if ((c > 0 && a[i] < 0) || (c < 0 && a[i] > 0)) {
        s += m;
        m = a[i];
        c *= -1;
        l = i;
      }
      m = max(m, a[i]);
    }
    s += m;
    cout << s << '\n';
  }
}
