#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, i;
    cin >> n;
    vector<long long> v(n);
    long long p = 0, q = -inf, cnt = 0, ans = 0, flag1 = 0, flag2 = 0;
    for (i = 0; i < n; i++) cin >> v[i];
    i = 0;
    while (1) {
      while (v[i] > 0) {
        p = max(p, v[i]);
        i++;
        flag1 = 1;
        cnt++;
        if (i == n) break;
      }
      if (flag1 == 1 && flag2 == 1) {
        ans += (p + q);
        p = 0;
        q = -inf;
        flag2 = 0;
        flag1 = 0;
      }
      while (v[i] < 0) {
        q = max(q, v[i]);
        i++;
        flag2 = 1;
        if (i == n) break;
      }
      if (flag1 == 1 && flag2 == 1) {
        ans += (p + q);
        p = 0;
        q = -inf;
        flag2 = 0;
        flag1 = 0;
      }
      if (i == n) break;
    }
    if (cnt == n || cnt == 0) {
      cout << ((p == 0) ? q : p) << endl;
      continue;
    }
    cout << ans << endl;
  }
  return 0;
}
