#include <bits/stdc++.h>
using namespace std;
int t, n;
long long a[200005];
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    long long ans = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    long long res1 = a[0];
    for (int i = 1; i < n; i++) {
      if (a[i] * res1 > 0) {
        res1 = max(res1, a[i]);
      } else {
        ans += res1;
        res1 = a[i];
      }
    }
    ans += res1;
    cout << ans << endl;
  }
  return 0;
}
