#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, b, c, i;
  char s;
  for (cin >> t; t--;) {
    cin >> s;
    for (b = c = i = 0; s == '+' || s == '-'; i++) {
      s == '-' ? (b ? b-- : (b = 0, c += (i + 1))) : b++;
      scanf("%c", &s);
    }
    c += i;
    cout << c << "\n";
  }
}
