#include <bits/stdc++.h>
using namespace std;
int ans[1000003];
void solve() {
  string s;
  cin >> s;
  int mr = 0;
  int best = 1000000000;
  int f = -1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '+')
      mr++;
    else
      mr--;
    if (mr < 0) {
      if (ans[abs(mr)] == 0) ans[abs(mr)] = i + 1;
    }
  }
  long long sum = 0;
  for (int i = 1; i <= s.size() + 1; i++) {
    if (ans[i] == 0) {
      sum += s.size();
      break;
    }
    sum += ans[i];
    ans[i] = 0;
  }
  cout << sum << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t > 0) {
    t--;
    solve();
  }
}
