#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
bool same(long long a, long long b) {
  return (((a < 0) && (b < 0)) || ((a > 0) && (b > 0)));
}
void work() {
  long long n;
  cin >> n;
  long long cur;
  cin >> cur;
  long long ans = (n == 1 ? cur : 0);
  for (long long i = 1; i < n; i++) {
    long long x;
    cin >> x;
    if (same(x, cur)) {
      cur = max(x, cur);
    } else {
      ans += cur;
      cur = x;
    }
  }
  ans += cur;
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long caeshi = 1;
  cin >> caeshi;
  for (long long z = 0; z < caeshi; ++z) work();
  return 0;
}
