#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<long long int> v(n);
    for (int i = 0; i < n; ++i) {
      cin >> v[i];
    }
    long long int sum = 0;
    for (int i = 0; i < n; ++i) {
      if (v[i] > 0) {
        long long int m = v[i];
        ++i;
        while (v[i] > 0) {
          m = max(m, v[i]);
          i++;
        }
        --i;
        sum += m;
      } else {
        long long int m = v[i];
        ++i;
        while (v[i] < 0) {
          m = max(m, v[i]);
          i++;
        }
        --i;
        sum += m;
      }
    }
    cout << sum << endl;
  }
}
