#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr << "Hello world!" << endl;
  long long T = 1, n, last, x;
  cin >> T;
  while (T--) {
    long long ans = 0;
    cin >> n;
    vector<long long> v;
    for (int i = 0; i < n; i++) cin >> x, v.push_back(x);
    last = v[0];
    for (int i = 1; i < n; i++) {
      if (last * v[i] < 0) {
        ans += last;
        last = v[i];
      } else
        last = max(last, v[i]);
    }
    ans += last;
    cout << ans << endl;
  }
  return 0;
}
