#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, m, k, mx = 0, mn = -1000000, sum = 0, a = -1, b = 0, l = 0,
                         r;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a > 0) {
      if (l == 1) {
        sum += mn;
        mn = -1000000;
        l = 0;
      }
      mx = max(mx, a);
      b = 1;
      if (i == n - 1) {
        if (b == 1) {
          sum += mx;
          mx = 0;
          b = 0;
        }
      }
    } else {
      if (b == 1) {
        sum += mx;
        mx = 0;
        b = 0;
      }
      mn = max(mn, a);
      l = 1;
      if (i == n - 1) {
        if (l == 1) {
          sum += mn;
          mn = -1000000;
          l = 0;
        }
      }
    }
  }
  cout << sum << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
