#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;
    if (arr[0] >= 0) {
      while (1) {
        long long int maxx = INT_MIN;
        long long int minn = INT_MIN;
        for (; i < n; i++) {
          if (arr[i] < 0)
            break;
          else {
            maxx = max(maxx, arr[i]);
          }
        }
        if (maxx != INT_MIN) vec.push_back(maxx);
        if (i == n) break;
        for (; i < n; i++) {
          if (arr[i] >= 0)
            break;
          else {
            minn = max(minn, arr[i]);
          }
        }
        if (minn != INT_MIN) vec.push_back(minn);
        if (i == n) break;
      }
    } else {
      while (1) {
        long long int maxx = INT_MIN;
        long long int minn = INT_MIN;
        for (; i < n; i++) {
          if (arr[i] < 0)
            break;
          else {
            maxx = max(maxx, arr[i]);
          }
        }
        if (maxx != INT_MIN) vec.push_back(maxx);
        if (i == n) break;
        for (; i < n; i++) {
          if (arr[i] >= 0)
            break;
          else {
            minn = max(minn, arr[i]);
          }
        }
        if (minn != INT_MIN) vec.push_back(minn);
        if (i == n) break;
      }
    }
    for (long long int i = 0; i < vec.size(); i++) sum += vec[i];
    cout << sum << endl;
  }
  return 0;
}
