#include <bits/stdc++.h>
using namespace std;
long long powermod(long long a, long long b) {
  if (b == 0) return 1;
  long long x = powermod(a, b / 2);
  x = x * x;
  if (b & 1) x = x * a;
  return x;
}
long long i, j, k;
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (i = (0); i < (n); i++) cin >> v[i];
  vector<long long> ans;
  vector<long long> sign(n, 0);
  for (i = (0); i < (n); i++) {
    if (v[i] > 0)
      sign[i] = 1;
    else
      sign[i] = -1;
  }
  for (i = 0; i < n; i++) {
    long long curr = v[i];
    long long j = i;
    while (j < n && sign[i] == sign[j]) {
      curr = max(curr, v[j]);
      j++;
    }
    ans.emplace_back(curr);
    i = j - 1;
  }
  long long sum = 0;
  for (auto it : ans) sum += it;
  cout << sum << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
