#include <bits/stdc++.h>
using namespace std;
bool sign(long long int n) { return n > 0; }
void solve() {
  long long int n, i, j, ans = 0;
  cin >> n;
  long long int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  long long int mx = 0;
  for (i = 0; i < n; i++) {
    mx = a[i];
    j = i;
    while (j < n && sign(a[j]) == sign(a[i])) {
      mx = max(a[j], mx);
      j++;
    }
    i = j - 1;
    ans += mx;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
