#include <bits/stdc++.h>
using namespace std;
const int maxn = (2e5) + 11;
const int MOD = (1e9) + 7;
const long long INF = (1e10) + 777;
const long double pi = 2 * acos(0.0);
const long long E9 = 1e9;
const long long E8 = 1e8;
const long long E7 = 1e7;
const long long E6 = 1e6;
const long long E5 = 1e5;
const long long E4 = 1e4;
const long long E3 = 1e3;
long long n, m, k, a[maxn];
string s;
long long cnt = 0, ans = 0;
void solve() {
  cnt = 0;
  cin >> n;
  long long mx = -INF;
  vector<long long> v;
  a[0] = -INF - 1;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] > 0) {
      while (a[i] > 0) {
        mx = max(mx, a[i]);
        i++;
      }
      v.push_back(mx);
      mx = -INF;
      i--;
    } else {
      while (a[i] < 0) {
        mx = max(mx, a[i]);
        i++;
      }
      i--;
      v.push_back(mx);
      mx = -INF;
    }
  }
  long long ans = 0;
  for (int i = 0; i < v.size(); ++i) {
    ans += v[i];
  }
  cout << ans << '\n';
}
int main() {
  int test = 1;
  cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}
