#include <bits/stdc++.h>
using namespace std;
class Debugger {
 public:
  template <typename T>
  Debugger &operator<<(const T &v) {
    cerr << v;
    return *this;
  }
  ~Debugger() { cerr << endl; }
};
template <typename T1, typename T2>
inline ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
inline ostream &operator<<(ostream &os, const array<T, N> &a) {
  bool first = true;
  os << "[";
  for (auto &v : a) {
    if (!first) os << ", ";
    os << v;
    first = false;
  }
  os << "]";
  return os;
}
template <typename T>
inline ostream &operator<<(ostream &os, const vector<T> &v) {
  bool first = true;
  os << "[";
  for (unsigned int i = 0; i < v.size(); i++) {
    if (!first) os << ", ";
    os << v[i];
    first = false;
  }
  return os << "]";
}
template <typename T>
inline ostream &operator<<(ostream &os, const set<T> &v) {
  bool first = true;
  os << "{";
  for (typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
    if (!first) os << ", ";
    os << *ii;
    first = false;
  }
  return os << "}";
}
template <typename T>
inline ostream &operator<<(ostream &os, const multiset<T> &v) {
  bool first = true;
  os << "{";
  for (typename multiset<T>::const_iterator ii = v.begin(); ii != v.end();
       ++ii) {
    if (!first) os << ", ";
    os << *ii;
    first = false;
  }
  return os << "}";
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &os, const map<T1, T2> &v) {
  bool first = true;
  os << "[";
  for (typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end();
       ++ii) {
    if (!first) os << ", ";
    os << *ii;
    first = false;
  }
  return os << "]";
}
const long long MOD = 998244353;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, 1, -1};
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long power_mod(long long x, long long y, long long p) {
  long long ans = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) ans = (ans * x) % p;
    y >>= 1;
    x = (x * x) % p;
  }
  return ans;
}
inline long long modInverse(long long n, long long p) {
  return power_mod(n, p - 2, p);
}
long long nCrModP(vector<long long> &fac, long long n, long long r,
                  long long p) {
  if (r == 0) return 1;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
template <typename T>
void print_vector(const vector<T> &v) {
  for (int i = 0; i < (((int)(v).size())); i++) {
    if (i > 0) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
string s;
int n;
bool cal(int cur) {
  for (int i = 0; i < (n); i++) {
    if (s[i] == '+')
      cur++;
    else
      cur--;
    if (cur < 0) return false;
  }
  return true;
}
long long solve() {
  cin >> s;
  n = s.size();
  int l = 0, r = n + 1, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (cal(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  if (ans == 0) return n;
  map<int, int> where;
  int cur = 0;
  for (int i = 0; i < (n); i++) {
    if (s[i] == '+')
      cur++;
    else
      cur--;
    if (where.count(cur) == 0) where[cur] = i;
  }
  long long t = 0;
  for (int i = 0; i < (ans); i++) {
    int val = -i - 1;
    int p = where[val];
    t += p + 1;
  }
  t += n;
  return t;
}
int main() {
  ios_base::sync_with_stdio(false);
  srand(time(NULL));
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(12);
  int cas;
  cin >> cas;
  for (int i = 0; i < (cas); i++) {
    cout << solve() << endl;
  }
}
