#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  long long res = 0, current = 0, mneg = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '+')
      current++;
    else
      current--;
    if (current < mneg) {
      res += (mneg - current) * (i + 1);
      mneg = current;
    }
  }
  cout << res + s.size() << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
