#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  vector<long long> pom;
  while (t != 0) {
    long long n;
    cin >> n;
    vector<int> v(n);
    for (int i(0); i < n; i++) cin >> v[i];
    if (n == 1) {
      cout << v[0] << endl;
    } else {
      int trenutni(v[0]);
      long long suma(0);
      for (int i(1); i < n; i++) {
        if (v[i] * trenutni > 0) {
          trenutni = max(trenutni, v[i]);
        } else {
          suma += trenutni;
          trenutni = v[i];
        }
      }
      suma += trenutni;
      pom.push_back(suma);
    }
    t--;
  }
  for (int i(0); i < pom.size(); i++) cout << pom[i] << endl;
}
