#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const long long modd1 = 1e9 + 7, modd2 = 998244353, maxn = 2011;
const double pi = acos(-1);
void solve() {
  long long t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    long long a[n + 4], i;
    for (i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    long long ans = a[1], last = a[1];
    for (i = 2; i <= n; ++i) {
      if (a[i] * a[i - 1] < 0) {
        ans += a[i];
        last = a[i];
      } else {
        if (a[i] > last) {
          ans -= last;
          ans += a[i];
          last = a[i];
        }
      }
    }
    cout << ans << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
