#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
signed main() {
  long long t;
  cin >> t;
  while (t-- > 0) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < (long long)(n); ++i) cin >> a[i];
    long long ans = 0;
    for (long long i = 0; i < (long long)(n); ++i) {
      long long x = -1e18;
      if (a[i] > 0) {
        while (i < n && a[i] > 0) {
          x = max(x, a[i]);
          ++i;
        }
        --i;
        ans += x;
      } else {
        while (i < n && a[i] < 0) {
          x = max(x, a[i]);
          ++i;
        }
        --i;
        ans += x;
      }
    }
    cout << ans << endl;
  }
}
