#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, xr = 0, i = 0;
    long long int ans1 = 0, ans2 = 0;
    cin >> n;
    vector<long long int> v1, v2;
    long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    while (i < n && a[i] > 0) i++;
    while (i < n) {
      long long int temp = -999999999999999;
      if (xr) {
        while (i < n && a[i] > 0) {
          temp = max(a[i], temp);
          i++;
        }
      } else {
        while (i < n && a[i] < 0) {
          temp = max(a[i], temp);
          i++;
        }
      }
      v1.push_back(temp);
      ans1 += temp;
      xr ^= 1;
    }
    xr = 1, i = 0;
    while (i < n && a[i] < 0) i++;
    while (i < n) {
      long long int temp = -999999999999999;
      if (xr) {
        while (i < n && a[i] > 0) {
          temp = max(a[i], temp);
          i++;
        }
      } else {
        while (i < n && a[i] < 0) {
          temp = max(a[i], temp);
          i++;
        }
      }
      v2.push_back(temp);
      xr ^= 1;
      ans2 += temp;
    }
    if (v1.size() > v2.size() || (v1.size() == v2.size() && ans1 > ans2))
      cout << ans1 << '\n';
    else
      cout << ans2 << '\n';
  }
}
