#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &it : a) {
      cin >> it;
    }
    int curr = a[0], sum = 0;
    bool p = a[0] > 0;
    for (auto i : a) {
      if (i > 0 != p) {
        sum += curr;
        curr = i;
        p = i > 0;
      } else {
        curr = max(curr, i);
      }
    }
    sum += curr;
    cout << sum << endl;
  }
  return 0;
}
