#include <bits/stdc++.h>
using namespace std;
void init() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
int main() {
  int test;
  int n;
  long long int x0, x1, sum, max;
  bool negative = false;
  cin >> test;
  for (int t = 0; t < test; t++) {
    cin >> n;
    cin >> x0;
    max = x0;
    sum = 0;
    if (x0 < 0) negative = true;
    for (int i = 0; i < n - 1; i++) {
      cin >> x1;
      if (negative) {
        if (x1 < 0) {
          if (x1 > max) max = x1;
        } else {
          sum += max;
          max = x1;
          negative = false;
        }
      } else {
        if (x1 > 0) {
          if (x1 > max) max = x1;
        } else {
          sum += max;
          max = x1;
          negative = true;
        }
      }
      cout << sum << " - ";
      x0 = x1;
    }
    sum += max;
    cout << sum << "\n";
  }
  return 0;
}
