#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int x;
  ll maxi = -pow(10, 9);
  ll sum = 0;
  int y;
  cin >> x;
  while (x--) {
    cin >> y;
    ll array[y];
    for (int i = 0; i < y; ++i) {
      cin >> array[i];
    }
    for (int j = 0; j < y - 1; ++j) {
      if (array[j] > maxi) {
        maxi = array[j];
      }
      if (j == y - 2 && ((array[j] > 0 && array[j + 1] > 0) ||
                         (array[j] < 0 && array[j + 1] < 0))) {
        sum = sum + max(maxi, array[j + 1]);
      }
      if (array[j] > 0 && array[j + 1] < 0 ||
          array[j] < 0 && array[j + 1] > 0) {
        if (j == y - 2) {
          sum = sum + array[y - 1];
        }
        sum = sum + maxi;
        maxi = -pow(10, 9);
      }
    }
    cout << sum << '\n';
    sum = 0;
    maxi = -pow(10, 9);
  }
}
