#include <bits/stdc++.h>
using namespace std;
int ma(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
int main() {
  int t;
  cin >> t;
  for (int k = 0; k < t; k++) {
    int n;
    long long ans = 0;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> v;
    v.push_back(0);
    for (int i = 1; i < n; i++) {
      if ((a[i - 1] < 0 && a[i] > 0) || (a[i - 1] > 0 && a[i] < 0))
        v.push_back(i);
    }
    v.push_back(n);
    for (int j = 0; j < v.size() - 1; j++) {
      int m = -1000000000;
      for (int i = v[j]; i < v[j + 1]; i++) {
        m = ma(a[i], m);
      }
      ans += m;
    }
    cout << ans << "\n";
  }
  return 0;
}
