#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long int> arr(n);
    for (int i = 0; i < n; ++i) cin >> arr[i];
    long long int sum = 0;
    int i = 0;
    while (i < n) {
      if (arr[i] < 0) {
        long long int tmp = INT_MIN;
        while (i < n && arr[i] < 0) {
          tmp = max(tmp, arr[i]);
          ++i;
        }
        sum += tmp;
      } else {
        long long int tmp = INT_MIN;
        while (i < n && arr[i] > 0) {
          tmp = max(tmp, arr[i]);
          ++i;
        }
        sum += tmp;
      }
    }
    cout << sum << endl;
  }
}
