#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 5;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    long long sum = 0;
    long long ma = a[0];
    for (int i = 1; i < n; ++i) {
      if ((a[i - 1] > 0 && a[i] < 0) || (a[i - 1] < 0 && a[i] > 0)) {
        sum += ma;
        ma = a[i];
      }
      ma = max(ma, a[i]);
    }
    sum += ma;
    cout << sum << '\n';
  }
  return 0;
}
