#include <bits/stdc++.h>
using namespace std;
int a[200020];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int sum, minn = -1e9, maxx = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] > 0) {
        maxx = max(maxx, a[i]);
      } else {
        minn = min(minn, a[i]);
      }
      if (a[i] > 0 && a[i - 1] < 0) {
        sum += minn;
        minn = -1e9;
      } else if (a[i] < 0 && a[i - 1] > 0) {
        sum += maxx;
        maxx = 0;
      }
    }
    if (minn != -1e9) {
      sum += minn;
    } else if (maxx) {
      sum += maxx;
    }
    cout << sum << endl;
  }
}
