#include <bits/stdc++.h>
using namespace std;
long long int n, t;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n;
    long long int a[n], x = 0;
    vector<long long int> ans;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i == 0) {
        ans.push_back(a[i]);
        continue;
      }
      long long int last = ans[ans.size() - 1];
      if ((a[i] > 0 && last < 0) || (last > 0 && a[i] < 0))
        ans.push_back(a[i]);
      else {
        ans[ans.size() - 1] = max(last, a[i]);
      }
    }
    long long int sum = 0;
    for (int i = 0; i < ans.size(); i++) {
      sum += ans[i];
    }
    cout << sum << endl;
  }
}
