#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    long long dpkp[n];
    long long dpkn[n];
    long long lenp[n];
    long long lenn[n];
    if (a[n - 1] > 0) {
      dpkp[n - 1] = a[n - 1];
      lenp[n - 1] = 1;
      lenn[n - 1] = 0;
      dpkn[n - 1] = 0;
    } else {
      dpkn[n - 1] = a[n - 1];
      lenn[n - 1] = 1;
      lenp[n - 1] = 0;
      dpkp[n - 1] = 0;
    }
    for (long long i = n - 2; i >= 0; i--) {
      if (a[i] > 0) {
        if (lenn[i + 1] + 1 > lenp[i + 1]) {
          dpkp[i] = dpkn[i + 1] + a[i];
        } else if (lenn[i + 1] + 1 < lenp[i + 1]) {
          dpkp[i] = dpkp[i + 1];
        } else {
          dpkp[i] = max(dpkp[i + 1], dpkn[i + 1] + a[i]);
        }
        lenp[i] = max(lenn[i + 1] + 1, lenp[i + 1]);
        lenn[i] = lenn[i + 1];
        if (lenn[i + 1] < lenp[i]) {
          dpkn[i] = INT_MIN;
        } else {
          dpkn[i] = dpkn[i + 1];
        }
      } else {
        if (lenp[i + 1] + 1 > lenn[i + 1]) {
          dpkn[i] = dpkp[i + 1] + a[i];
        } else if (lenp[i + 1] + 1 < lenn[i + 1]) {
          dpkn[i] = dpkn[i + 1];
        } else {
          dpkn[i] = max(dpkn[i + 1], dpkp[i + 1] + a[i]);
        }
        lenn[i] = max(lenp[i + 1] + 1, lenn[i + 1]);
        lenp[i] = lenp[i + 1];
        if (lenp[i + 1] < lenn[i]) {
          dpkp[i] = INT_MIN;
        } else {
          dpkp[i] = dpkp[i + 1];
        }
      }
    }
    if (lenp[0] == lenn[0]) {
      cout << max(dpkp[0], dpkn[0]) << endl;
    } else if (lenp[0] > lenn[0]) {
      cout << dpkp[0] << endl;
    } else {
      cout << dpkn[0] << endl;
    }
  }
  return 0;
}
