#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000000 + 7;
long long int arr[200005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, sum = 0;
    cin >> n;
    for (long long int i = 0; i < n; i++) cin >> arr[i];
    long long int i = 0;
    vector<long long int> vec;
    while (1) {
      long long int maxp = INT_MIN;
      long long int maxn = INT_MIN;
      for (; i < n; i++) {
        if (arr[i] < 0)
          break;
        else {
          maxp = max(maxp, arr[i]);
        }
      }
      if (maxp != INT_MIN) vec.push_back(maxp);
      if (i == n) break;
      for (; i < n; i++) {
        if (arr[i] >= 0)
          break;
        else {
          maxn = max(maxn, arr[i]);
        }
      }
      if (maxn != INT_MIN) vec.push_back(maxn);
      if (i == n) break;
    }
    for (long long int i = 0; i < vec.size(); i++) sum += vec[i];
    cout << sum << endl;
  }
  return 0;
}
