#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
      int a;
      cin >> a;
      if (v.empty()) {
        v.push_back(a);
      } else if (signbit(v.back()) == signbit(a) > 0 && v.back() < a) {
        v.pop_back();
        v.push_back(a);
      } else if (v.back() * a < 0) {
        v.push_back(a);
      }
    }
    long long int sum = 0;
    for (int i : v) {
      sum += i;
    }
    cout << sum << '\n';
  }
  return 0;
}
