#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    vector<ll> w;
    while (n--) {
      ll x;
      cin >> x;
      w.push_back(x);
    }
    if (w.size() == 1) {
      cout << w[0] << endl;
      continue;
    }
    vector<ll> v;
    ll k = 1, a = 0, b = 0;
    ll pos = 0, neg = -1e12;
    for (int i = 0; i < w.size(); i++) {
      if (k == 1) {
        pos = 0, neg = -1e12;
        k = 0;
      }
      if (i == 0) {
        if (w[i] > 0 && w[i + 1] < 0) {
          v.push_back(w[i]);
          a = 1;
          b = 0;
        } else if (w[i] < 0 && w[i + 1] > 0) {
          v.push_back(w[i]);
          b = 1;
          a = 0;
        } else if (w[i] > 0) {
          pos = max(pos, w[i]);
          a = 1;
          b = 0;
        } else if (w[i] < 0) {
          neg = max(neg, w[i]);
          b = 1, a = 0;
        }
      } else if (i == w.size() - 1) {
        if (a == 1) {
          if (w[i] < 0) {
            v.push_back(w[i]);
            b = 1;
            a = 0;
          } else if (w[i] > 0) {
            ll c = max(pos, w[i]);
            v.push_back(c);
            a = 1;
            b = 0;
          }
        } else if (b == 1) {
          if (w[i] > 0) {
            v.push_back(w[i]);
            a = 1;
            b = 0;
          } else if (w[i] < 0) {
            ll c = max(neg, w[i]);
            v.push_back(c);
            b = 1;
            a = 0;
          }
        }
      } else {
        if (a == 1) {
          if (w[i] < 0 && w[i + 1] > 0) {
            v.push_back(w[i]);
            b = 1;
            a = 0;
            k = 1;
          } else if (w[i] > 0 && w[i + 1] < 0) {
            ll c = max(pos, w[i]);
            v.push_back(c);
            a = 1;
            b = 0;
            k = 1;
          } else if (w[i] > 0) {
            pos = max(pos, w[i]);
            a = 1;
            b = 0;
          } else if (w[i] < 0) {
            neg = max(neg, w[i]);
            b = 1, a = 0;
          }
        } else if (b == 1) {
          if (w[i] > 0 && w[i + 1] < 0) {
            v.push_back(w[i]);
            a = 1;
            b = 0;
            k = 1;
          } else if (w[i] < 0 && w[i + 1] > 0) {
            ll c = max(neg, w[i]);
            v.push_back(c);
            b = 1;
            a = 0;
            k = 1;
          } else if (w[i] > 0) {
            pos = max(pos, w[i]);
            a = 1;
            b = 0;
          } else if (w[i] < 0) {
            neg = max(neg, w[i]);
            b = 1, a = 0;
          }
        }
      }
    }
    ll sum = 0;
    for (auto it : v) sum += it;
    cout << sum << endl;
  }
  return 0;
}
