#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (int hh = 0; hh < q; hh++) {
    long long x;
    cin >> x;
    long long a[x], s = 0;
    vector<long long> v, v1;
    for (int i = 0; i < x; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < x; i++) {
      if (a[i] > 0 && a[i + 1] < 0 && i < x && i + 1 < x) {
        v.push_back(a[i]);
        sort(v.rbegin(), v.rend());
        s = s + v[0];
        v.clear();
      } else if (a[i] < 0 && a[i + 1] > 0 && i < x && i + 1 < x) {
        v1.push_back(a[i]);
        sort(v1.rbegin(), v1.rend());
        s = s + v1[0];
        v1.clear();
      } else if (a[i] > 0 && i + 1 == x) {
        v.push_back(a[i]);
      } else if (a[i] < 0 && i + 1 == x) {
        v1.push_back(a[i]);
      } else if (a[i] > 0) {
        v.push_back(a[i]);
      } else {
        v1.push_back(a[i]);
      }
    }
    if (v.size() > 0) {
      sort(v.rbegin(), v.rend());
      s = s + v[0];
      v.clear();
    } else if (v1.size() > 0) {
      sort(v1.rbegin(), v1.rend());
      s = s + v1[0];
      v1.clear();
    }
    cout << s << endl;
  }
}
