#include <bits/stdc++.h>
using namespace std;
const long long int maxn = INT_MAX;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<int> v(n);
    for (long long int i = 0; i < n; ++i) cin >> v[i];
    long long int s = 0, e = 0;
    vector<int> m;
    long long int ans = 0;
    while (e < n) {
      long long int m1 = 0;
      while (v[e] * v[e + 1] > 0 and e < n - 1) {
        e++;
      }
      long long int m = INT_MIN;
      for (int i = s; i <= e; i++) {
        m = (m > v[i]) ? m : v[i];
      }
      ans += m;
      s = e + 1;
      e = e + 1;
    }
    cout << ans << "\n";
  }
  return 0;
}
