#include <bits/stdc++.h>
using namespace std;
signed main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    if (n == 1) {
      cout << a[0] << endl;
      continue;
    }
    bool isP;
    a[0] > 0 ? isP = 1 : isP = 0;
    int curr_best;
    curr_best = a[0];
    long long sum = 0;
    for (int i = 1; i < n; i++) {
      if (a[i] > 0 && isP) {
        curr_best = max(curr_best, a[i]);
      } else if (a[i] < 0 && isP) {
        sum += curr_best;
        isP = 0;
        curr_best = a[i];
      } else if (a[i] < 0 && !isP) {
        curr_best = max(a[i], curr_best);
      } else if (a[i] > 0 && !isP) {
        sum += curr_best;
        isP = 1;
        curr_best = a[i];
      }
    }
    sum += curr_best;
    cout << sum << endl;
  }
}
