#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long signum(long long x) {
  if (x == 0)
    return 0;
  else if (x < 0)
    return -1;
  else
    return 1;
}
using ii = pair<long long, long long>;
int32_t main() {
  long long tc;
  cin >> tc;
  while (tc--) {
    long long N;
    cin >> N;
    vector<long long> v(N);
    for (auto& e : v) cin >> e;
    long long ans = 0, cur = v[0];
    for (long long i = 1; i < N; ++i) {
      if (signum(v[i]) * signum(v[i - 1]) > 0) {
        cur = max(cur, v[i]);
      } else {
        ans += cur;
        cur = v[i];
      }
    }
    ans += cur;
    cout << ans << "\n";
  }
}
