#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& it : a) cin >> it;
    long long maxSum = 0;
    long long currMaxElement = a[0];
    for (int j = 1; j < n; ++j) {
      if ((a[j - 1] > 0 && a[j] > 0) || (a[j - 1] < 0 && a[j] < 0)) {
        if (a[j] > currMaxElement) {
          currMaxElement = a[j];
        }
      } else {
        maxSum += currMaxElement;
        currMaxElement = a[j];
      }
      if (j == n - 1) {
        maxSum += currMaxElement;
      }
    }
    cout << maxSum << endl;
  }
  return 0;
}
