#include <bits/stdc++.h>
using namespace std;
mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return mt_rnd_64() % (r - l + 1) + l; }
const long long N = 1e6 + 10;
const long long inf = 1e18 + 10;
long long a[N];
signed main() {
  long long q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    long long ans = 0;
    long long mx = -inf;
    for (long long i = 1; i <= n; ++i) {
      cin >> a[i];
      if (i > 1) {
        if ((a[i] < 0 && a[i - 1] < 0) || (a[i] > 0 && a[i - 1] > 0))
          mx = max(mx, a[i]);
        else {
          ans += mx;
          mx = a[i];
        }
      } else
        mx = a[i];
    }
    cout << ans + max(mx, a[n]) << '\n';
  }
  return 0;
}
