#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const long long maxn = 201110;
const long long M = 1e9 + 7;
long long n, m, k, ok;
long long a[maxn];
signed main() {
  long long T;
  cin >> T;
  while (T--) {
    cin >> n;
    for (long long i = 1; i <= n; i++) {
      cin >> a[i];
    }
    bool flag = 1;
    long long e = 0;
    long long ans = 0;
    for (long long i = 1; i <= n; i++) {
      if (flag) {
        if (a[i] > 0) {
          e = max(e, a[i]);
        } else {
          flag = 0;
          ans += e;
          e = a[i];
        }
      } else {
        if (a[i] > 0) {
          flag = 1;
          ans += e;
          e = a[i];
        } else {
          e = max(e, a[i]);
        }
      }
    }
    ans += e;
    cout << ans << endl;
  }
  return 0;
}
