#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n);
    for (auto &x : v) cin >> x;
    long long Max = v[0], sum = 0;
    bool pos = (v[0] > 0) ? true : false;
    for (long long i = 1; i < n; i++) {
      if (pos == true && v[i] > 0) {
        Max = max(Max, v[i]);
      } else if (pos == false && v[i] < 0) {
        Max = max(Max, v[i]);
      } else if (pos == true && v[i] < 0) {
        sum += Max;
        Max = v[i];
        pos = false;
      } else if (pos == false && v[i] > 0) {
        sum += Max;
        Max = v[i];
        pos = true;
      }
      if (i == n - 1) sum += Max;
    }
    cout << sum << "\n";
  }
  return 0;
}
