#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int k = 0; k < t; k++) {
    int n;
    cin >> n;
    int arr[n];
    int maxlength = 1;
    vector<int> changes;
    changes.push_back(0);
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (i != 0 &&
          ((arr[i] > 0 && arr[i - 1] < 0) || (arr[i] < 0 && arr[i - 1] > 0))) {
        maxlength++;
        changes.push_back(i);
      }
    }
    long long sum = 0;
    for (int i = 0; i < changes.size() - 1; i++) {
      int best = -INF;
      for (int j = changes[i]; j < changes[i + 1]; j++) {
        if (arr[j] > best) best = arr[j];
      }
      if (best != -INF) sum += 1ll * best;
    }
    int best = -INF;
    for (int i = changes[changes.size() - 1]; i < n; i++) {
      if (arr[i] > best) best = arr[i];
    }
    if (best != -INF) sum += 1ll * best;
    cout << sum << "\n";
  }
}
