#include <bits/stdc++.h>

using namespace std;
long long mxm()
{
    return LLONG_MIN;
}
template<typename... Args>
long long mxm(long long a, Args... args)
{
    return max(a,mxm(args...));
}

long long mnm()
{
    return LLONG_MAX;
}
template<typename... Args>
long long mnm(long long a, Args... args)
{
    return min(a,mnm(args...));
}

template<class T> ostream& operator<<(ostream& os,vector<T> V)
{
    os<<"[ ";
    for(auto v:V)os<<v<<", ";
    return os<<"]";
}
template<class T> ostream& operator<<(ostream& os,set<T> V)
{
    os<<"[ ";
    for(auto v:V)os<<v<<", ";
    return os<<"]";
}
template<class T> ostream& operator<<(ostream& os,multiset<T> V)
{
    os<<"[ ";
    for(auto v:V)os<<v<<", ";
    return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P)
{
    return os<<"("<<P.first<<","<<P.second<<")";
}
long long pct(long long x)
{
    return __builtin_popcount(x);
}
long long bits(long long x)
{
    return 31-__builtin_clz(x);
}
long long cdiv(long long a, long long b)
{
    return a/b+!(a<0||a%b == 0);
}
long long fstTrue(function<bool(long long)> f, long long lo, long long hi)
{
    hi ++;
    assert(lo <= hi);
    while (lo < hi)
    {
        long long mid = (lo+hi)/2;
        f(mid) ? hi = mid : lo = mid+1;
    }
    return lo;
}
void setIn(string s)
{
    freopen(s.c_str(),"r",stdin);
}
void setOut(string s)
{
    freopen(s.c_str(),"w",stdout);
}
void unsyncIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}
void setIO(string s = "")
{
    unsyncIO();

    if (s.size())
    {
        setIn(s+".in"), setOut(s+".out");
    }
}
typedef int32_t start;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long bf(string a)
{
    long long res=0;
    long long cnt=0;
    for(long long i=0; i<1000; i++)
    {
        long long cur=i;
        bool ok=1;
        for(long long j=0; j<a.length(); j++)
        {
            res++;
            if(a[j]== '+')
            {
                cur++;
            }
            else
            {
                cur--;
            }
            if(cur<0)
            {
                ok=false;
                break;
            }
        }

        if(ok)break;
    }
    return res;
}

long long fast(string a)
{
    long long bal=0;
    long long mini=0;
    long long meat=1;
    bool notfound=1;
    map<long long,long long> temp;
    for(long long i=0; i<a.length(); i++)
    {
        if(a[i]=='+')bal++;
        else bal--;
        if(bal<0 and temp.find(bal)==temp.end())
        {
            temp[bal]=i+1;
        }
    }
    long long res=a.length();
    for(auto x:temp)
    {

        res+=x.second;
    }

    return res;
}

string gen(long long n)
{
    string res="";
    for(long long i=0; i<n; i++)
    {
        res.push_back(rand()%2==0?'+':'-');
    }
    return res;
}
start main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(NULL));
    long long t;
    cin >> t;
    while(t--)
    {
        string a;
        cin >> a;
        cout<<fast(a)<<'\n';
    }

    if(1)
    {
        for(long long kk=0; kk<=1000; kk++)
        {
            long long pp=34;
            long long up=20;
            long long cp=13*23;
            pp=up+cp;
            pp=up+cp;
            pp=up+cp;
        }
    }
    return 0;
}


// Problem : C. Pluses and Minuses
// Contest : Codeforces - Educational Codeforces Round 90 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1373/problem/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//replace_junk
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <cmath>
#include <ctime>
#include <numeric>
#include <bits/stdc++.h>
//replace_junk
using namespace std;
#define int						long long
#define	pii						pair<int,int>
#define	vpii					vector<pii>
#define	vi						vector<int>
#define	pb						push_back
#define bg						begin()
#define ed						end()
#define ln						length()
#define S						second
#define sz						size()
#define nl						cout<<'\n';
#define all(x)					x.begin(),x.end()
#define endl 					'\n'
#define F						first
#define rep0(n)					for(int i=0;i<n;i++)
#define rep0j(n)				for(int j=0;j<n;j++)
#define QQ						<<" "<<
#define oo(x)					cout<<x<<endl;
#define take(a,n) 				vi a(n);rep0(n){cin>>a[i];}
#define dbl_io(x)				cout<< fixed << setprecision(x)
#define IOS						ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int mxm() {return LLONG_MIN;}
template<typename... Args>
int mxm(int a, Args... args) { return max(a,mxm(args...)); }

int mnm() {return LLONG_MAX;}
template<typename... Args>
int mnm(int a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<", ";return os<<"]";
}
template<class T> ostream& operator<<(ostream& os,set<T> V){
	os<<"[ ";for(auto v:V)os<<v<<", ";return os<<"]";
}
template<class T> ostream& operator<<(ostream& os,multiset<T> V){
	os<<"[ ";for(auto v:V)os<<v<<", ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}
int pct(int x) { return __builtin_popcount(x); }
int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0
int fstTrue(function<bool(int)> f, int lo, int hi) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		int mid = (lo+hi)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	// cin.exceptions(cin.failbit);
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (s.sz) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}
typedef int32_t start;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int bf(string a){
	int res=0;
	int cnt=0;
	rep0(1000){
		int cur=i;
		bool ok=1;
		for(int j=0;j<a.ln;j++){
			res++;
			if(a[j]== '+'){
				cur++;
			}else{
				cur--;
			}
			if(cur<0){
				ok=false;
				break;
			}
		}

		if(ok)break;
	}
	return res;
}

int fast(string a){
	int bal=0;
	int mini=0;
	int meat=1;
	bool notfound=1;
	map<int,int> temp;
	rep0(a.ln){
		if(a[i]=='+')bal++;
		else bal--;
		if(bal<0 and temp.find(bal)==temp.ed){
			temp[bal]=i+1;
		}
	}
	int res=a.ln;
	for(auto x:temp){

		res+=x.second;
	}

	return res;
}

string gen(int n){
	string res="";
	rep0(n){
		res.pb(rand()%2==0?'+':'-');
	}
	return res;
}
start main(){
	IOS
	srand(time(NULL));
	int t;
	cin >> t;
	while(t--){
		string a;
		cin >> a;
//		oo(bf(a))
		oo(fast(a))
	}
	//add_junk
	//add_junk
	// rep0(100){
		// string a=gen(5);
		// if(bf(a)!=fast(a)){
			// oo(a)
			// break;
		// }
	// }
	return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = 5 * 1e5;
ll mod = 5;

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll sum_digits(ll n)
{
	ll ret = 0;
	while (n)
	{
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

ll gcd(ll a, ll b)
{
	if (a == 0)
		return b;
	else
		return gcd(b % a, a);
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here

int main()
{
	IOS;
	ll t, n, r;
	cin >> t;
	string s;
	while (t--)
	{
		cin >> s;
		ll res = 0;
		ll cur = 0;
		ll mn = 0;
		for (int i = 0; i < s.length(); ++i)
		{
			++res;
			if (s[i] == '+')
				++cur;
			else
				--cur;
			if (cur < 0)
			{
				res += i+1;
				cur=0;
			}
		}
		cout << res << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = (2 * 1e6 + 3);
ll mod = (1e9 + 7);

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here

int main()
{
	IOS;
	ll t, a;
	cin >> t;
	string s;
	while (t--)
	{
		cin >> s;
		a = s.length();
		int cmin=0, cplus=0;
		ll k = 0;
		for (int i = 0; i < s.length(); ++i)
		{
			if (s[i] == '-')
				++cmin;
			else
				++cplus;
		}

		ll ans = 0,cm=0,cp=0;
		for (int i = 0; i <= cmin - cplus; ++i)
		{
			for (; k < s.length(); ++k)
			{
				if (s[k] == '+')
					cp++;
				else
					cm++;
				if (cm>cp+i)
				{
					break;
				}
			}
			ans += min(k + 1, a);
			++k;
		}
		cout << max(a,ans) << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = (2 * 1e6 + 3);
ll mod = (1e9 + 7);

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here

int main()
{
	IOS;
	int t,a,b,c;
	cin >> t;
	string s;
	while (t--)
	{
		cin >> s;
		a = s.length();
		int cmin=0, cplus=0;
		int k = a;
		bool notset = true;
		for (int i = 0; i < s.length(); ++i)
		{
			if (s[i] == '-')
				++cmin;
			else
				++cplus;
			if (notset && cmin > cplus)
			{
				notset = false;
				k = i;
			}
		}

		ll ans = 0,count=0;
		bool flag;
		for (int i = 0; i <= cmin - cplus; ++i)
		{
			ans += min(k + 1,a);
			count = 0;
			++k;
			for (; k < s.length(); ++k)
			{
				if (s[k] == '+')
					count++;
				else
					count--;
				if (count < 0)
				{
					flag = false;
					break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = (2 * 1e6 + 3);
ll mod = (1e9 + 7);

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here

int main()
{
	IOS;
	ll t, a, b, c;
	cin >> t;
	string s;
	while (t--)
	{
		cin >> s;
		a = s.length();
		int cmin=0, cplus=0;
		ll k = 0;
		bool notset = true;
		for (int i = 0; i < s.length(); ++i)
		{
			if (s[i] == '-')
				++cmin;
			else
				++cplus;
		}

		ll ans = 0,cm=0,cp=0;
		bool flag;
		for (int i = 0; i <= cmin - cplus; ++i)
		{

			for (; k < s.length(); ++k)
			{
				if (s[k] == '+')
					cp++;
				else
					cm++;
				if (cm>cp+i)
				{
					break;
				}
			}
			ans += min(k + 1, a);
			++k;
		}
		cout << max(a,ans) << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = (2 * 1e6 + 3);
ll mod = (1e9 + 7);

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here

int main()
{
	IOS;
	ll t, a, b, c;
	cin >> t;
	string s;
	while (t--)
	{
		cin >> s;
		a = s.length();
		int cmin=0, cplus=0;
		ll k = a;
		bool notset = true;
		for (int i = 0; i < s.length(); ++i)
		{
			if (s[i] == '-')
				++cmin;
			else
				++cplus;
			if (notset && cmin > cplus)
			{
				notset = false;
				k = i;
			}
		}

		ll ans = 0,count=0;
		bool flag;
		for (int i = 0; i <= cmin - cplus; ++i)
		{
			ans += min(k + 1,a);
			count = 0;
			++k;
			for (; k < s.length(); ++k)
			{
				if (s[k] == '+')
					count++;
				else
					count--;
				if (count < 0)
				{
					flag = false;
					break;
				}
			}
		}
		cout << max(a,ans) << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = (2 * 1e6 + 3);
ll mod = (1e9 + 7);

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here

int main()
{
	IOS;
	ll t, a;
	cin >> t;
	string s;
	while (t--)
	{
		cin >> s;
		a = s.length();
		int cmin=0, cplus=0;
		for (int i = 0; i < s.length(); ++i)
		{
			if (s[i] == '-')
				++cmin;
			else
				++cplus;
		}

		ll ans = 0,cm=0,cp=0;
		for (int i = 0; i <= cmin - cplus; ++i)
		{
			int cur = i;
			bool ok = true;
			for (int k=0; k < s.length(); ++k)
			{
				ans += 1;
				if (s[k] == '+')
					++cur;
				else
					--cur;
				if (cur<0)
				{
					ok = false;
					break;
				}

			}
			if (ok)
				break;

		}
		cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = (2 * 1e6 + 3);
ll mod = (1e9 + 7);

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here

int main()
{
	IOS;
	ll t, a;
	cin >> t;
	string s;
	while (t--)
	{
		cin >> s;
		a = s.length();
		int cmin=0, cplus=0;
		for (int i = 0; i < s.length(); ++i)
		{
			if (s[i] == '-')
				++cmin;
			else
				++cplus;
		}

		ll ans = 0,cm=0,cp=0;
		for (int i = 0; i <= cmin - cplus; ++i)
		{
			int cur = i;
			bool ok = true;
			for (int k=0; k < s.length(); ++k)
			{
				ans += 1;
				if (s[k] == '+')
					++cur;
				else
					--cur;
				if (cur<0)
				{
					ok = false;
					break;
				}

			}
			if (ok)
				break;

		}
		cout <<max(a,ans) << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
#define pb push_back
#define input l1 t;cin>>t;while(t--)
int main() {
        input{
           string s;
           cin>>s;
           l1 res =0;
           l1 i=0;
           l1 n = s.length();
           if(count(s.begin(),s.end(),'-')==0){
              cout<<n<<endl;
           }
           else if(count(s.begin(),s.end(),'+')==0){
              cout<< ((n*(n+1))/2)+n<<endl;
           }
           else{
               l1 curr =0;
               l1 ans=0;
               for(l1 j=0;j<s.length();j++){
                   if(s[j]=='+')
                     curr = curr+1;
                   else
                    curr= curr-1;
                   if(curr<0){
                       ans +=i+1;
                   }
               }
               cout<<ans+n<<endl;
           }
        }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
#define pb push_back
#define input l1 t;cin>>t;while(t--)
int main() {
        input{
           string s;
           cin>>s;
           l1 res =0;
           l1 i=0;
           l1 n = s.length();
               l1 curr =0;
               l1 ans=0;
               for(l1 j=0;j<s.length();j++){
                   if(s[j]=='+')
                     curr = curr+1;
                   else
                    curr= curr-1;
                   if(curr<0){
                       ans +=j+1;
                       curr=0;
                   }
               }
               cout<<ans+n<<endl;
        }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
#define pb push_back
#define input l1 t;cin>>t;while(t--)
int main() {
        input{
           string s;
           cin>>s;
           l1 res =0;
           l1 i=0;
           while(i>=0){
               l1 curr =i;
               bool ok = true;
               for(l1 j=0;j<s.length();j++){
                   res=res+1;
                   if(s[j]=='+')
                     curr = curr+1;
                   else
                    curr= curr-1;
                   if(curr<0){
                       ok = false;
                       break;
                   }
               }
              if(ok){
               break;
              }
              i++;
           }
            cout<<res<<endl;
        }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
#define pb push_back
#define input l1 t;cin>>t;while(t--)
int main() {
        input{
           string s;
           cin>>s;
           l1 res =0;
           l1 i=0;
           l1 n = s.length();
           if(count(s.begin(),s.end(),'-')==0){
              cout<<n<<endl;
           }
           else if(count(s.begin(),s.end(),'+')==0){
              cout<< ((n*(n+1))/2)+n<<endl;
           }
           else{
               l1 curr =0;
               l1 ans=0;
               for(l1 j=0;j<s.length();j++){
                   if(s[j]=='+')
                     curr = curr+1;
                   else
                    curr= curr-1;
                   if(curr<0){
                       ans +=j+1;
                   }
               }
               cout<<ans+n<<endl;
           }
        }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
#define pb push_back
#define input l1 t;cin>>t;while(t--)
int main() {
        input{
           string s;
           cin>>s;
           l1 res =0;
           l1 i=0;
           l1 n = s.length();
               l1 curr =0;
               l1 ans=0;
               for(l1 j=0;j<s.length();j++){
                   if(s[j]=='+')
                     curr = curr+1;
                   else
                    curr= curr-1;
                   if(curr<0){
                       ans +=j+1;
                   }
               }
               cout<<ans+n<<endl;
        }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
#define pb push_back
#define input l1 t;cin>>t;while(t--)
int main() {
        input{
           string s;
           cin>>s;
           l1 res =0;
           l1 i=0;
           l1 n = s.length();
           if(count(s.begin(),s.end(),'-')==0){
              cout<<n<<endl;
           }
           else if(count(s.begin(),s.end(),'+')==0){
              cout<< ((n*(n+1))/2)+n<<endl;
           }
           else{
           while(i>=0){
               l1 curr =i;
               bool ok = true;
               for(l1 j=0;j<s.length();j++){
                   res=res+1;
                   if(s[j]=='+')
                     curr = curr+1;
                   else
                    curr= curr-1;
                   if(curr<0){
                       ok = false;
                       break;
                   }
               }
              if(ok){
               break;
              }
              i++;
           }
            cout<<res<<endl;
           }
        }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
#define pb push_back
#define input l1 t;cin>>t;while(t--)
int main() {
        input{
           string s;
           cin>>s;
           l1 res =0;
           l1 i=0;
           l1 n = s.length();
           if(count(s.begin(),s.end(),'-')==0){
              cout<<(n*(n+1))/2<<endl;
           }
           else{
           while(i>=0){
               l1 curr =i;
               bool ok = true;
               for(l1 j=0;j<s.length();j++){
                   res=res+1;
                   if(s[j]=='+')
                     curr = curr+1;
                   else
                    curr= curr-1;
                   if(curr<0){
                       ok = false;
                       break;
                   }
               }
              if(ok){
               break;
              }
              i++;
           }
            cout<<res<<endl;
           }
        }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
#define pb push_back
#define input l1 t;cin>>t;while(t--)
int main() {
        input{
           string s;
           cin>>s;
           l1 res =0;
           l1 i=0;
           l1 n = s.length();
           if(count(s.begin(),s.end(),'-')==0){
              cout<<((n*(n+1))/2)+n<<endl;
           }
           else{
           while(i>=0){
               l1 curr =i;
               bool ok = true;
               for(l1 j=0;j<s.length();j++){
                   res=res+1;
                   if(s[j]=='+')
                     curr = curr+1;
                   else
                    curr= curr-1;
                   if(curr<0){
                       ok = false;
                       break;
                   }
               }
              if(ok){
               break;
              }
              i++;
           }
            cout<<res<<endl;
           }
        }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    string s;
    ll res;
    bool ok;
    ll curr;
    while(t--){
        cin>>s;
         res=0;
        for(ll i=0;i<LLONG_MAX;i++){
            curr=i;
            ok=true;
            if(curr<s.length()){

            for(i=0;i<s.length();i++){
                res++;
                if(s[i]=='+'){
                    curr++;
                    }

                 else{

                     curr--;}

                if(curr<0){
                    ok=false;
                    break;
                    }
                }
            }else{
                res+=s.length();
                }

            if(ok){
                break;
                }

            }

        cout<<res<<"\n";
        }
    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    string s;
    ll res;
    bool ok;
    ll curr;
    while(t--){
        cin>>s;
         res=0;
        for(ll i=0;i<1000000;i++){
            curr=i;
            ok=true;

            for(i=0;i<s.length();i++){
                res++;
                if(s[i]=='+'){
                    curr++;
                    }

                 else{

                     curr--;}

                if(curr<0){
                    ok=false;
                    break;
                    }
                }

            if(ok){
                break;
                }
         }

            cout<<res<<"\n";
        }
    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    string s;
    ll res;
    bool ok;
    ll curr;
    while(t--){
        cin>>s;
         res=0;
        for(ll i=0;;i++){
            curr=i;
            ok=true;
            for(i=0;i<s.length();i++){
                res++;
                if(s[i]=='+'){
                    curr++;
                    }

                 if(s[i]=='-'){

                     curr--;}

                if(curr<0){
                    ok=false;
                    break;
                    }
                }

            if(ok){
                break;
                }

            }

        cout<<res<<"\n";
        }
    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    string s;
    ll res;
    bool ok;
    ll curr;
    while(t--){
        cin>>s;
         res=0;
        for(ll i=0;;i++){
            curr=i;
            ok=true;
            for(i=0;i<s.length();i++){
                res++;
                if(s[i]=='+'){
                    curr++;
                    }

                 else{

                     curr--;}

                if(curr<0){
                    ok=false;
                    break;
                    }
                }

            if(ok){
                break;
                }

            }

        cout<<res<<"\n";
        }
    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    string s;
    ll res;
    bool ok;
    ll curr;
    while(t--){
        cin>>s;
         res=0;
        for(ll i=0;i<LLONG_MAX;i++){
            curr=i;
            ok=true;
            for(i=0;i<s.length();i++){
                res++;
                if(s[i]=='+'){
                    curr++;
                    }

                 else{

                     curr--;}

                if(curr<0){
                    ok=false;
                    break;
                    }
                }

            if(ok){
                break;
                }

            }

        cout<<res<<"\n";
        }
    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    string s;
    ll res;
    bool ok;
    ll curr;
    while(t--){
        cin>>s;
         res=0;
        for(ll i=0;i<1000000000000;i++){
            curr=i;
            ok=true;

            for(i=0;i<s.length();i++){
                res++;
                if(s[i]=='+'){
                    curr++;
                    }

                 else{

                     curr--;}

                if(curr<0){
                    ok=false;
                    break;
                    }
                }

            if(ok){
                break;
                }
         }

            cout<<res<<"\n";
        }
    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    string s;

    while(t--){
         cin>>s;
     ll curr=0,mn=0,res=s.length();
     for(ll i=0;i<s.length();i++){
         if(s[i]=='+'){
             curr++;
             }else{
                 curr--;
                 }
         if(curr<mn){
             mn=curr;
             res+=i+1;
             }
         }
       cout<<res<<"\n";
       }
    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    string s;
    ll res;
    bool ok;
    ll curr;
    while(t--){
        cin>>s;
         res=0;
        for(ll i=0;i<INT_MAX;i++){
            curr=i;
            ok=true;
            for(i=0;i<s.length();i++){
                res++;
                if(s[i]=='+'){
                    curr++;
                    }

                 else{

                     curr--;}

                if(curr<0){
                    ok=false;
                    break;
                    }
                }

            if(ok){
                break;
                }

            }

        cout<<res<<"\n";
        }
    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    string s;
    ll res;
    bool ok;
    ll curr;
    while(t--){
        cin>>s;
         res=0;
        for(ll i=0;i<LLONG_MAX;i++){
            curr=i;
            ok=true;
            if(curr<s.length()){

            for(i=0;i<s.length();i++){
                res++;
                if(s[i]=='+'){
                    curr++;
                    }

                 else{

                     curr--;}

                if(curr<0){
                    ok=false;
                    break;
                    }
                }
            }else{
                break;
                }

            if(ok){
                break;
                }

            }

        cout<<res<<"\n";
        }
    return 0;
    }


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int main()
{
    w(t)
    {
        string s;
        cin>>s;
        int pre[s.size()];
        if( s[0] == '+') pre[0] = 1;
        else pre[0] = -1;
        for(int i=1; i<s.size(); i++){
            pre[i] = pre[i-1];
            if( s[i] == '+') pre[i]++;
            else pre[i]--;
        }
        int ans = s.size();
        int cur = 0;
        int save = 0;
        for(int i=0; i<s.size(); i++){

            save++;
            if( pre[i] == -1*(cur +1)){
                ans += save;
                cur++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define ll            long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int main()
{

    w(t)
    {
        string s;
        cin>>s;
        ll n=s.length();
        ll dp[n];
        for(ll i=0;i<n;i++)
        {
            if(s[i]=='-')
                dp[i]=-1;

            else
                dp[i]=1;

        }
        for(ll i=1;i<n;i++)
        {
            dp[i] +=dp[i-1];
        }
        unordered_map<ll,ll>seen;
        for(ll i=0;i<n;i++)
        {
            if(seen.find(dp[i])==seen.end())
            {
                seen[dp[i]]=i;
            }
        }
        ll mini=1e12;
        for(ll i=0;i<n;i++)
        {
            mini=min(mini,dp[i]);
        }
        if(mini>=0)
        {
            cout<<n<<endl;
            continue;
        }

        ll len=abs(mini);
        ll ans=0;
        for(ll i=0;i<=len;i++)
        {
            ll temp=(i+1)*-1;
            if(seen.find(temp)==seen.end())
                ans+=n;
            else{
                ll tl=seen[temp]+1;
                ans+=tl;
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int32_t main()
{
    w(t)
    {
        string s;
        cin>>s;
        int cur = 0;
        int ans = s.size();
        for(int i=0; i<s.size(); i++){
            if( s[i] == '+') cur++;
            else cur--;
            if( cur < 0){
                ans += (i+1);
                cur = 0;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int32_t main()
{
    w(t)
    {
        string s;
        cin>>s;
        int pre[s.size()];
        if( s[0] == '+') pre[0] = 1;
        else pre[0] = -1;
        for(int i=1; i<s.size(); i++){
            pre[i] = pre[i-1];
            if( s[i] == '+') pre[i]++;
            else pre[i]--;
        }
        int ans = s.size();
        int cur = 0;
        int save = 0;
        for(int i=0; i<s.size(); i++){

            save++;
            if( pre[i] == -1*(cur +1)){
                ans += save;
                cur++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int32_t main()
{

    w(t)
    {
        string s;
        cin>>s;
        int n = s.size();
        int a[n];
        if( s[0] == '-') a[0] = -1;
        else a[0] = 1;
        int flag = 0;
        if( a[0] < 0) flag = 1;
        for(int i=1; i<n; i++){
            if( s[i] == '-') a[i] = a[i-1] - 1;
            else a[i] = a[i+1] + 1;
            if( a[i] < 0) {
                flag = 1;
            }
        }
        if( flag == 0){
            cout<<n<<endl;
            continue;
        }
        else{
            int k = INT_MIN;
            int ans = 0;
            for(int i=0; i<n; i++) a[i] = -1*a[i], k = max(a[i], k);
            ans = n + k;
            for(int i=0; i<n; i++){
                if( a[i] >= 0 and a[i] < k){
                    ans += i+1;
                    continue;
                }
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int32_t main()
{

    w(t)
    {
        string s;
        cin>>s;
        int n = s.size();
        int a[n];
        if( s[0] == '-') a[0] = -1;
        else a[0] = 1;
        int flag = 0;
        if( a[0] < 0) flag = 1;
        for(int i=1; i<n; i++){
            if( s[i] == '-') a[i] = a[i-1] - 1;
            else a[i] = a[i+1] + 1;
            if( a[i] < 0) {
                flag = 1;
            }
        }
        if( flag == 0){
            cout<<n<<endl;
            continue;
        }
        else{
            int k = INT_MIN;
            int ans = 0;
            int k1;
            for(int i=0; i<n; i++){
                a[i] = -1*a[i];
                if( a[i] > k){
                    k1 = i+1;
                    k = a[i];
                }
            }
            ans = n;
            for(int i=k1; i>0; i--){
                ans += i;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int32_t main()
{

    w(t)
    {
        string s;
        cin>>s;
        int n = s.size();
        // cout<<n<<endl;
        int a[n];
        if( s[0] == '-') a[0] = -1;
        else a[0] = 1;
        int flag = 0;
        if( a[0] < 0) flag = 1;
        for(int i=1; i<n; i++){
            if( s[i] == '-') a[i] = a[i-1] - 1;
            else a[i] = a[i-1] + 1;
            if( a[i] < 0) {
                flag = 1;
            }
        }
        if( flag == 0){
            // cout<<'n';
            cout<<n<<endl;
            continue;
        }
        else{
            // cout<<"asfsdf";
            int k = INT_MIN;
            int ans = 0;
            int k1;
            for(int i=0; i<n; i++){
                a[i] = -1*a[i];
                if( a[i] > k){
                    k1 = i+1;
                    k = a[i];
                }
            }
            ans = n;
            for(int i=k1, j=k-1; i>0 and j>=0; j--, i--){
                ans += i;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int32_t main()
{

    w(t)
    {
        string s;
        cin>>s;
        int n = s.size();
        int a[n];
        if( s[0] == '-') a[0] = -1;
        else a[0] = 1;
        int flag = 0;
        if( a[0] < 0) flag = 1;
        for(int i=1; i<n; i++){
            if( s[i] == '-') a[i] = a[i-1] - 1;
            else a[i] = a[i+1] + 1;
            if( a[i] < 0) {
                flag = 1;
            }
        }
        if( flag == 0){
            cout<<n<<endl;
            continue;
        }
        else{
            int k = INT_MIN;
            int ans = 0;
            int k1;
            for(int i=0; i<n; i++){
                a[i] = -1*a[i];
                if( a[i] > k){
                    k1 = i+1;
                    k = a[i];
                }
            }
            ans = n;
            for(int i=k1, j=k-1; i>0 and j>=0; j--, i--){
                ans += i;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i,n) for(int i=0;i<n;++i)
#define rf(i,n) for(int i=n-1;i>=0;--1)
#define ms(x,a) memset(x,a,sizeof(x))
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define opi1(a) printf("%d\n",a)
#define opi2(a,b) printf("%d %d",a,b)
#define opi3(a,b,c) printf("%d %d %d",a,b,c)
#define ipi1(a) scanf("%d",&a)
#define ipi2(a,b) scanf("%d%d",&a,&b)
#define opl1(a) printf("%ld\n",a)
#define opl2(a,b) printf("%ld %ld",a,b)
#define opl3(a,b,c) printf("%ld %ld %ld",a,b,c)
#define ipl1(a) scanf("%ld",&a)
#define ipl2(a,b) scanf("%ld%ld",&a,&b)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<int>::iterator viit;
typedef vector<float> vf;
typedef vector<float>::iterator vfit;
typedef vector<char> vc;
typedef vector<char>::iterator vcit;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return 1; } return 0; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return 1; } return 0; }

#define PI 3.141592653589793
#define MOD 1000000007

inline int read()
{
	int res = 0, f = 1;
	char c = getchar();
	while((c<48 || c>57) && c != '-') c = getchar();
	if(c == '-') f = -1, c = getchar();
	while(c>47 && c<58) res = (res<<3)+(res<<1)+(c^48), c = getchar();

	return res*f;
}

void solve()
{
    str s; cin>>s;
    ll curr=0,res=0,i=0;

    while(i<s.length())
    {
        ++res;
        bool ok=1;
        if(s[i]=='+') ++curr;
        else          --curr;

        if(curr<0)
        {
            ++curr;
            res+=i+1;
            ok=0;
        }

        if(curr<0 and ok) break;
        ++i;
    }
    cout<<res<<endl;
}

int main()
{
    FAST
    int t; cin>>t;

   while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i,n) for(int i=0;i<n;++i)
#define rf(i,n) for(int i=n-1;i>=0;--1)
#define ms(x,a) memset(x,a,sizeof(x))
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define opi1(a) printf("%d\n",a)
#define opi2(a,b) printf("%d %d",a,b)
#define opi3(a,b,c) printf("%d %d %d",a,b,c)
#define ipi1(a) scanf("%d",&a)
#define ipi2(a,b) scanf("%d%d",&a,&b)
#define opl1(a) printf("%ld",a)
#define opl2(a,b) printf("%ld %ld",a,b)
#define opl3(a,b,c) printf("%ld %ld %ld",a,b,c)
#define ipl1(a) scanf("%ld",&a)
#define ipl2(a,b) scanf("%ld%ld",&a,&b)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<int>::iterator viit;
typedef vector<float> vf;
typedef vector<float>::iterator vfit;
typedef vector<char> vc;
typedef vector<char>::iterator vcit;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return 1; } return 0; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return 1; } return 0; }

#define PI 3.141592653589793
#define MOD 1000000007

inline int read()
{
	int res = 0, f = 1;
	char c = getchar();
	while((c<48 || c>57) && c != '-') c = getchar();
	if(c == '-') f = -1, c = getchar();
	while(c>47 && c<58) res = (res<<3)+(res<<1)+(c^48), c = getchar();

	return res*f;
}

void solve()
{
    str s; cin>>s;
    ll curr=0,res=0,i=0;

    while(i<s.length())
    {
        ++res;
        bool ok=1;
        if(s[i]=='+') ++curr;
        else          --curr;

        if(curr<0)
        {
            ++curr;
            res+=i+1;
            ok=0;
        }

        if(curr<0 and ok) break;
        ++i;
    }
    opl1(res);
}

int main()
{
    FAST
    int t; cin>>t;

   while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i,n) for(int i=0;i<n;++i)
#define rf(i,n) for(int i=n-1;i>=0;--1)
#define ms(x,a) memset(x,a,sizeof(x))
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define opi1(a) printf("%d\n",a)
#define opi2(a,b) printf("%d %d",a,b)
#define opi3(a,b,c) printf("%d %d %d",a,b,c)
#define ipi1(a) scanf("%d",&a)
#define ipi2(a,b) scanf("%d%d",&a,&b)
#define opl1(a) printf("%ld\n",a)
#define opl2(a,b) printf("%ld %ld",a,b)
#define opl3(a,b,c) printf("%ld %ld %ld",a,b,c)
#define ipl1(a) scanf("%ld",&a)
#define ipl2(a,b) scanf("%ld%ld",&a,&b)
#define endl "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define ln printf("\n")
#define sp <<" "<<
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<int>::iterator viit;
typedef vector<float> vf;
typedef vector<float>::iterator vfit;
typedef vector<char> vc;
typedef vector<char>::iterator vcit;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return 1; } return 0; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return 1; } return 0; }

#define PI 3.141592653589793
#define MOD 1000000007

inline int read()
{
	int res = 0, f = 1;
	char c = getchar();
	while((c<48 || c>57) && c != '-') c = getchar();
	if(c == '-') f = -1, c = getchar();
	while(c>47 && c<58) res = (res<<3)+(res<<1)+(c^48), c = getchar();

	return res*f;
}

void solve()
{
    str s; cin>>s;
    ll cur=0,res=0,threshold=0;

    f(i,s.length())
    {
        //++res;
        if(s[i]=='+') ++cur;
        else          --cur;

        if(cur<threshold)
        {
            threshold=cur;
            res+=i+1;
        }
    }
    res+=s.length();
    cout<<res<<endl;
}

int main()
{
    FAST
    int t; cin>>t;

    while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i,n) for(int i=0;i<n;++i)
#define rf(i,n) for(int i=n-1;i>=0;--1)
#define ms(x,a) memset(x,a,sizeof(x))
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define opi1(a) printf("%d\n",a)
#define opi2(a,b) printf("%d %d",a,b)
#define opi3(a,b,c) printf("%d %d %d",a,b,c)
#define ipi1(a) scanf("%d",&a)
#define ipi2(a,b) scanf("%d%d",&a,&b)
#define opl1(a) printf("%ld",a)
#define opl2(a,b) printf("%ld %ld",a,b)
#define opl3(a,b,c) printf("%ld %ld %ld",a,b,c)
#define ipl1(a) scanf("%ld",&a)
#define ipl2(a,b) scanf("%ld%ld",&a,&b)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<int>::iterator viit;
typedef vector<float> vf;
typedef vector<float>::iterator vfit;
typedef vector<char> vc;
typedef vector<char>::iterator vcit;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return 1; } return 0; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return 1; } return 0; }

#define PI 3.141592653589793
#define MOD 1000000007

inline int read()
{
	int res = 0, f = 1;
	char c = getchar();
	while((c<48 || c>57) && c != '-') c = getchar();
	if(c == '-') f = -1, c = getchar();
	while(c>47 && c<58) res = (res<<3)+(res<<1)+(c^48), c = getchar();

	return res*f;
}

void solve()
{
    str s; cin>>s;
    int curr=0,res=0,i=0;

    while(i<s.length())
    {
        ++res;
        bool ok=1;
        if(s[i]=='+') ++curr;
        else          --curr;

        if(curr<0)
        {
            ++curr;
            res+=i+1;
            ok=0;
        }

        if(curr<0 and ok) break;
        ++i;
    }
    opi1(res);
}

int main()
{
    FAST
    int t; cin>>t;

   while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i,n) for(int i=0;i<n;++i)
#define rf(i,n) for(int i=n-1;i>=0;--1)
#define ms(x,a) memset(x,a,sizeof(x))
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define opi1(a) printf("%d\n",a)
#define opi2(a,b) printf("%d %d",a,b)
#define opi3(a,b,c) printf("%d %d %d",a,b,c)
#define ipi1(a) scanf("%d",&a)
#define ipi2(a,b) scanf("%d%d",&a,&b)
#define opl1(a) printf("%ld",a)
#define opl2(a,b) printf("%ld %ld",a,b)
#define opl3(a,b,c) printf("%ld %ld %ld",a,b,c)
#define ipl1(a) scanf("%ld",&a)
#define ipl2(a,b) scanf("%ld%ld",&a,&b)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<int>::iterator viit;
typedef vector<float> vf;
typedef vector<float>::iterator vfit;
typedef vector<char> vc;
typedef vector<char>::iterator vcit;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return 1; } return 0; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return 1; } return 0; }

#define PI 3.141592653589793
#define MOD 1000000007

inline int read()
{
	int res = 0, f = 1;
	char c = getchar();
	while((c<48 || c>57) && c != '-') c = getchar();
	if(c == '-') f = -1, c = getchar();
	while(c>47 && c<58) res = (res<<3)+(res<<1)+(c^48), c = getchar();

	return res*f;
}

void solve()
{
    str s; cin>>s;
    ll curr=0,res=0,i=0;

    while(i<s.length())
    {
        ++res;
        bool ok=1;
        if(s[i]=='+') ++curr;
        else          --curr;

        if(curr<0)
        {
            ++curr;
            res+=i+1;
            ok=0;
        }

        if(curr<0 and ok) break;
        ++i;
    }
    opi1(res);
}

int main()
{
    FAST
    int t; cin>>t;

   while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i,n) for(int i=0;i<n;++i)
#define rf(i,n) for(int i=n-1;i>=0;--1)
#define ms(x,a) memset(x,a,sizeof(x))
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define opi1(a) printf("%d\n",a)
#define opi2(a,b) printf("%d %d",a,b)
#define opi3(a,b,c) printf("%d %d %d",a,b,c)
#define ipi1(a) scanf("%d",&a)
#define ipi2(a,b) scanf("%d%d",&a,&b)
#define opl1(a) printf("%ld\n",a)
#define opl2(a,b) printf("%ld %ld",a,b)
#define opl3(a,b,c) printf("%ld %ld %ld",a,b,c)
#define ipl1(a) scanf("%ld",&a)
#define ipl2(a,b) scanf("%ld%ld",&a,&b)
#define endl "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define ln printf("\n")
#define sp <<" "<<
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<int>::iterator viit;
typedef vector<float> vf;
typedef vector<float>::iterator vfit;
typedef vector<char> vc;
typedef vector<char>::iterator vcit;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return 1; } return 0; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return 1; } return 0; }

#define PI 3.141592653589793
#define MOD 1000000007

inline int read()
{
	int res = 0, f = 1;
	char c = getchar();
	while((c<48 || c>57) && c != '-') c = getchar();
	if(c == '-') f = -1, c = getchar();
	while(c>47 && c<58) res = (res<<3)+(res<<1)+(c^48), c = getchar();

	return res*f;
}

void solve()
{
    str s; cin>>s;
    ll cur=0,res=0,threshold=0;

    f(i,s.length())
    {
        //++res;
        if(s[i]=='+') ++cur;
        else          --cur;

        if(cur<threshold)
        {
            threshold=cur;
            res+=i+1;
        }
    }
    res+=s.length();
    opl1(res);
}

int main()
{
    FAST
    int t; cin>>t;

    while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i,n) for(int i=0;i<n;++i)
#define rf(i,n) for(int i=n-1;i>=0;--1)
#define ms(x,a) memset(x,a,sizeof(x))
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define opi1(a) printf("%d\n",a)
#define opi2(a,b) printf("%d %d",a,b)
#define opi3(a,b,c) printf("%d %d %d",a,b,c)
#define ipi1(a) scanf("%d",&a)
#define ipi2(a,b) scanf("%d%d",&a,&b)
#define opl1(a) printf("%ld",a)
#define opl2(a,b) printf("%ld %ld",a,b)
#define opl3(a,b,c) printf("%ld %ld %ld",a,b,c)
#define ipl1(a) scanf("%ld",&a)
#define ipl2(a,b) scanf("%ld%ld",&a,&b)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<int>::iterator viit;
typedef vector<float> vf;
typedef vector<float>::iterator vfit;
typedef vector<char> vc;
typedef vector<char>::iterator vcit;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return 1; } return 0; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return 1; } return 0; }

#define PI 3.141592653589793
#define MOD 1000000007

inline int read()
{
	int res = 0, f = 1;
	char c = getchar();
	while((c<48 || c>57) && c != '-') c = getchar();
	if(c == '-') f = -1, c = getchar();
	while(c>47 && c<58) res = (res<<3)+(res<<1)+(c^48), c = getchar();

	return res*f;
}

void solve()
{
    str s; cin>>s;
    int r=0,i=0;

    while(1)
    {
        int cur=i;
        bool ok=1;
        f(j,s.length())
        {
            ++r;
            if(s[j]=='+') ++cur;
            else --cur;

            if(cur<0)
            {
                ok=0;
                break;
            }
        }
        ++i;
        if(ok) break;
    }
    opi1(r);
}

int main()
{
    FAST
    int t; cin>>t;

   while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i,n) for(int i=0;i<n;++i)
#define rf(i,n) for(int i=n-1;i>=0;--1)
#define ms(x,a) memset(x,a,sizeof(x))
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define opi1(a) printf("%d\n",a)
#define opi2(a,b) printf("%d %d",a,b)
#define opi3(a,b,c) printf("%d %d %d",a,b,c)
#define ipi1(a) scanf("%d",&a)
#define ipi2(a,b) scanf("%d%d",&a,&b)
#define opl1(a) printf("%ld\n",a)
#define opl2(a,b) printf("%ld %ld",a,b)
#define opl3(a,b,c) printf("%ld %ld %ld",a,b,c)
#define ipl1(a) scanf("%ld",&a)
#define ipl2(a,b) scanf("%ld%ld",&a,&b)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<int>::iterator viit;
typedef vector<float> vf;
typedef vector<float>::iterator vfit;
typedef vector<char> vc;
typedef vector<char>::iterator vcit;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return 1; } return 0; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return 1; } return 0; }

#define PI 3.141592653589793
#define MOD 1000000007

inline int read()
{
	int res = 0, f = 1;
	char c = getchar();
	while((c<48 || c>57) && c != '-') c = getchar();
	if(c == '-') f = -1, c = getchar();
	while(c>47 && c<58) res = (res<<3)+(res<<1)+(c^48), c = getchar();

	return res*f;
}

void solve()
{
    str s; cin>>s;
    ll curr=0,res=0,i=0;

    while(i<s.length())
    {
        ++res;
        bool ok=1;
        if(s[i]=='+') ++curr;
        else          --curr;

        if(curr<0)
        {
            ++curr;
            res+=i+1;
            ok=0;
        }

        if(curr<0 and ok) break;
        ++i;
    }
    opl1(res);
}

int main()
{
    FAST
    int t; cin>>t;

   while(t--) solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define FOR(i, a, b) for (auto i {a}; i < b; i++) // a = i's initial value, b = limit
#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(), x.end()
#define all_(x) x.rbegin(), x.rend()

const ll MOD = 1000000007;
const int INF = 1034567890;
const ll LL_INF = 1234567890123456789ll;
const double PI = acos(-1);
const long double ERR = 1E-10;

int factorial(int n){
		return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
	}

ll GCD(vector<ll> v){
    ll result = v[0];
    int n = v.size();
    FOR(i, 1, n)
    {
        result = __gcd(v[i], result);
        if(result == 1) return 1;
    }
    return result;
}

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

vector<int> primeFactors(int n)
{
	vector<int> v;
    while (n % 2 == 0){
        v.PB(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2){
        while (n % i == 0){
            v.PB(i);
            n = n/i;
        }
    }
    if (n > 2)
        v.PB(n);
    return v;
}

bool sortcol( const vector<int>& v1,
               const vector<int>& v2 ) {
 return v1[0] < v2[0];
}

int main(){

    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        int n = s.length();
        int cur = 0, mn = 0, res = n;
        FOR(i, 0, n){
            if(s[i] == '+') cur++;
            else cur--;
            if(cur < mn){
                mn = cur;
                res += i + 1;
            }
        }
        cout << res << endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define FOR(i, a, b) for (auto i {a}; i < b; i++) // a = i's initial value, b = limit
#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(), x.end()
#define all_(x) x.rbegin(), x.rend()

const ll MOD = 1000000007;
const int INF = 1034567890;
const ll LL_INF = 1234567890123456789ll;
const double PI = acos(-1);
const long double ERR = 1E-10;

int factorial(int n){
		return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
	}

ll GCD(vector<ll> v){
    ll result = v[0];
    int n = v.size();
    FOR(i, 1, n)
    {
        result = __gcd(v[i], result);
        if(result == 1) return 1;
    }
    return result;
}

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

vector<int> primeFactors(int n)
{
	vector<int> v;
    while (n % 2 == 0)
    {
        v.PB(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            v.PB(i);
            n = n/i;
        }
    }
    if (n > 2)
        v.PB(n);
    return v;
}

bool sortcol( const vector<int>& v1,
               const vector<int>& v2 ) {
 return v1[0] < v2[0];
}

int main(){

    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        ll n = s.length();
        ll cp{count(s.begin(), s.end(), '+')};
        ll res = 0;
        ll fp = s.find('+');
        if(cp == 0){
            fp = n;
        }
        ll diff = 0;
        res += fp*(fp + 1) / 2;
        for(ll i = fp; i < n; i++){
            if(s[i] == '+'){
                if(s[i - 1] == '-') diff = 1;
                else diff++;
            }else{
                diff--;
            }
            if(diff < 0) res += i + 1;
        }
        res += n;
        cout << res << endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define FOR(i, a, b) for (auto i {a}; i < b; i++) // a = i's initial value, b = limit
#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(), x.end()
#define all_(x) x.rbegin(), x.rend()

const ll MOD = 1000000007;
const int INF = 1034567890;
const ll LL_INF = 1234567890123456789ll;
const double PI = acos(-1);
const long double ERR = 1E-10;

int factorial(int n){
		return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
	}

ll GCD(vector<ll> v){
    ll result = v[0];
    int n = v.size();
    FOR(i, 1, n)
    {
        result = __gcd(v[i], result);
        if(result == 1) return 1;
    }
    return result;
}

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

vector<int> primeFactors(int n)
{
	vector<int> v;
    while (n % 2 == 0)
    {
        v.PB(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            v.PB(i);
            n = n/i;
        }
    }
    if (n > 2)
        v.PB(n);
    return v;
}

bool sortcol( const vector<int>& v1,
               const vector<int>& v2 ) {
 return v1[0] < v2[0];
}

int main(){

    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        ll n = s.length();
        ll cp{count(s.begin(), s.end(), '+')};
        ll res = 0;
        ll fp = s.find('+');
        ll diff = 0;
        if(cp > 0) res += fp*(fp + 1) / 2;
        FOR(i, fp, n){
            if(s[i] == '+'){
                diff++;
            }else{
                diff--;
            }
            if(diff < 0) res += i + 1;
        }
        res += n;
        cout << res << endl;

    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define FOR(i, a, b) for (auto i {a}; i < b; i++) // a = i's initial value, b = limit
#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(), x.end()
#define all_(x) x.rbegin(), x.rend()

const ll MOD = 1000000007;
const int INF = 1034567890;
const ll LL_INF = 1234567890123456789ll;
const double PI = acos(-1);
const long double ERR = 1E-10;

int factorial(int n){
		return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
	}

ll GCD(vector<ll> v){
    ll result = v[0];
    int n = v.size();
    FOR(i, 1, n)
    {
        result = __gcd(v[i], result);
        if(result == 1) return 1;
    }
    return result;
}

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

vector<int> primeFactors(int n)
{
	vector<int> v;
    while (n % 2 == 0)
    {
        v.PB(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            v.PB(i);
            n = n/i;
        }
    }
    if (n > 2)
        v.PB(n);
    return v;
}

bool sortcol( const vector<int>& v1,
               const vector<int>& v2 ) {
 return v1[0] < v2[0];
}

int main(){

    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        ll n = s.length();
        ll cp{count(s.begin(), s.end(), '+')};
        ll res = 0;

        ll fp = s.find('+');
        if(cp == 0){ fp = 3;}
        ll diff = 0;
        res += fp*(fp + 1) / 2;
        FOR(i, fp, n){
            if(s[i] == '+'){
                diff++;
            }else{
                diff--;
            }
            if(diff < 0) res += i + 1;
        }
        res += n;
        cout << res << endl;

    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define FOR(i, a, b) for (auto i {a}; i < b; i++) // a = i's initial value, b = limit
#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(), x.end()
#define all_(x) x.rbegin(), x.rend()

const ll MOD = 1000000007;
const int INF = 1034567890;
const ll LL_INF = 1234567890123456789ll;
const double PI = acos(-1);
const long double ERR = 1E-10;

int factorial(int n){
		return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
	}

ll GCD(vector<ll> v){
    ll result = v[0];
    int n = v.size();
    FOR(i, 1, n)
    {
        result = __gcd(v[i], result);
        if(result == 1) return 1;
    }
    return result;
}

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

vector<int> primeFactors(int n)
{
	vector<int> v;
    while (n % 2 == 0){
        v.PB(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2){
        while (n % i == 0){
            v.PB(i);
            n = n/i;
        }
    }
    if (n > 2)
        v.PB(n);
    return v;
}

bool sortcol( const vector<int>& v1,
               const vector<int>& v2 ) {
 return v1[0] < v2[0];
}

int main(){

    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        ll n = s.length();
        ll cur = 0, mn = 0, res = n;
        for (ll i = 0; i < n; ++i)
        {
            if(s[i] == '+') cur++;
            else cur--;
            if(cur < mn){
                mn = cur;
                res += i + 1;
            }
        }
        cout << res << endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define FOR(i, a, b) for (auto i {a}; i < b; i++) // a = i's initial value, b = limit
#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(), x.end()
#define all_(x) x.rbegin(), x.rend()

const ll MOD = 1000000007;
const int INF = 1034567890;
const ll LL_INF = 1234567890123456789ll;
const double PI = acos(-1);
const long double ERR = 1E-10;

int factorial(int n){
		return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
	}

ll GCD(vector<ll> v){
    ll result = v[0];
    int n = v.size();
    FOR(i, 1, n)
    {
        result = __gcd(v[i], result);
        if(result == 1) return 1;
    }
    return result;
}

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

vector<int> primeFactors(int n)
{
	vector<int> v;
    while (n % 2 == 0)
    {
        v.PB(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            v.PB(i);
            n = n/i;
        }
    }
    if (n > 2)
        v.PB(n);
    return v;
}

bool sortcol( const vector<int>& v1,
               const vector<int>& v2 ) {
 return v1[0] < v2[0];
}

int main(){

    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        ll n = s.length();
        ll cp{count(s.begin(), s.end(), '+')};
        ll res = 0;
        ll fp = s.find('+');
        if(cp == 0){ fp = n;}
        ll diff = 0;
        res += fp*(fp + 1) / 2;
        FOR(i, fp, n){
            if(s[i] == '+'){
                diff++;
            }else{
                diff--;
            }
            if(diff < 0) res += i + 1;
        }
        res += n;
        cout << res << endl;

    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define FOR(i, a, b) for (auto i {a}; i < b; i++) // a = i's initial value, b = limit
#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(), x.end()
#define all_(x) x.rbegin(), x.rend()

const ll MOD = 1000000007;
const int INF = 1034567890;
const ll LL_INF = 1234567890123456789ll;
const double PI = acos(-1);
const long double ERR = 1E-10;

int factorial(int n){
		return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
	}

ll GCD(vector<ll> v){
    ll result = v[0];
    int n = v.size();
    FOR(i, 1, n)
    {
        result = __gcd(v[i], result);
        if(result == 1) return 1;
    }
    return result;
}

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

vector<int> primeFactors(int n)
{
	vector<int> v;
    while (n % 2 == 0)
    {
        v.PB(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            v.PB(i);
            n = n/i;
        }
    }
    if (n > 2)
        v.PB(n);
    return v;
}

bool sortcol( const vector<int>& v1,
               const vector<int>& v2 ) {
 return v1[0] < v2[0];
}

int main(){

    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        ll n = s.length();
        ll cp{};
        ll cm{};
        ll res = 0;
        ll fp = s.find('+');
        ll diff = 0;
        res += fp*(fp + 1) / 2;
        FOR(i, fp, n){
            if(s[i] == '+'){
                diff++;
            }else{
                diff--;
            }
            if(diff < 0) res += i + 1;
        }
        res += n;
        cout << res << endl;

    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define FOR(i, a, b) for (auto i {a}; i < b; i++) // a = i's initial value, b = limit
#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(), x.end()
#define all_(x) x.rbegin(), x.rend()

const ll MOD = 1000000007;
const int INF = 1034567890;
const ll LL_INF = 1234567890123456789ll;
const double PI = acos(-1);
const long double ERR = 1E-10;

int factorial(int n){
		return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
	}

ll GCD(vector<ll> v){
    ll result = v[0];
    int n = v.size();
    FOR(i, 1, n)
    {
        result = __gcd(v[i], result);
        if(result == 1) return 1;
    }
    return result;
}

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

vector<int> primeFactors(int n)
{
	vector<int> v;
    while (n % 2 == 0)
    {
        v.PB(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            v.PB(i);
            n = n/i;
        }
    }
    if (n > 2)
        v.PB(n);
    return v;
}

bool sortcol( const vector<int>& v1,
               const vector<int>& v2 ) {
 return v1[0] < v2[0];
}

int main(){

    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        ll n = s.length();
        ll cp{count(s.begin(), s.end(), '+')};
        ll res = 0;
        ll fp = s.find('+');
        if(cp == 0){
            fp = n;
        }
        ll diff = 0;
        res += fp*(fp + 1) / 2;
        for(ll i = fp; i < n; i++){
            if(s[i] == '+'){
                diff++;
            }else{
                diff--;
            }
            if(diff < 0) res += i + 1;
        }
        res += n;
        cout << res << endl;
    }

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t;
	cin>>t;
	while(t--){
	   string s;
	   cin>>s;
	   ll res=0;
	   ll curr=0;

	   for(ll i=0;i<s.length();i++){

	       if(s[i]=='+')
	       curr++;
	       else
	       curr--;
	       if(curr<0){
	           curr++;
	           res+=i+1;
	       }
	   }

	   cout<<res+s.length()<<'\n';
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t;
	cin>>t;
	while(t--){
	   string s;
	   cin>>s;
	   int res=s.length();
	   ll n=0;
	   ll p=0;
	   for(ll i=0;i<s.length();i++){
	       if(s[i]=='-')
	       n++;
	       else
	       p++;
	   }
	   if(n>p)
	   res+=((n-p)*(n-p+1))/2;

	   cout<<res<<'\n';
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t;
	cin>>t;
	while(t--){
	   string s;
	   cin>>s;
	   int res=0;
	   ll curr=0;

	   for(ll i=0;i<s.length();i++){
	       res++;
	       if(s[i]=='+')
	       curr++;
	       else
	       curr--;
	       if(curr<0){
	           curr++;
	           res+=i+1;
	       }
	   }

	   cout<<res<<'\n';
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t;
	cin>>t;
	while(t--){
	   string s;
	   cin>>s;
	   int res=0;
	   ll curr=0;

	   for(ll i=0;i<s.length();i++){
	       res++;
	       if(s[i]=='+')
	       curr++;
	       else
	       curr--;
	       if(curr<0){
	           curr++;
	           res+=i+1;
	       }
	   }

	   res+=s.length();
	   cout<<res<<'\n';
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t;
	cin>>t;
	while(t--){
	   string s;
	   cin>>s;
	   int res=0;
	   ll i=0;
	   while(1){
	       ll curr=i;
	       bool ok=true;
	       for(ll j=0;j<s.length();j++){
	           res++;
	           if(s[j]=='+')
	           curr++;
	           else
	           curr--;
	           if(curr<0)
	           {
	               ok=false;
	               break;
	           }

	       }
	       if(ok)
	       break;
	       i++;
	   }
	   cout<<res<<'\n';
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t;
	cin>>t;
	while(t--){
	   string s;
	   cin>>s;
	   int res=0;
	   ll curr=0;

	   for(ll i=0;i<s.length();i++){

	       if(s[i]=='+')
	       curr++;
	       else
	       curr--;
	       if(curr<0){
	           curr++;
	           res+=i+1;
	       }
	   }

	   cout<<res+s.length()<<'\n';
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t;
	cin>>t;
	while(t--){
	   string s;
	   cin>>s;
	   int res=0;
	   ll curr=0;

	   for(ll i=0;i<s.length();i++){

	       if(s[i]=='+')
	       curr++;
	       else
	       curr--;
	       if(curr<0){
	           curr++;
	           res+=(i+1);
	       }
	   }

	   cout<<res+s.length()<<'\n';
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t;
	cin>>t;
	while(t--){
	   string s;
	   cin>>s;
	   int res=0;
	   ll curr=0;

	   for(ll i=0;i<s.length();i++){
	       if(s[i]=='+')
	       curr++;
	       else
	       curr--;
	       if(curr<0){
	           curr++;
	           res+=i+1;
	       }
	   }

	   cout<<res<<'\n';
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		int n=s.size();
		int a[2][n];
		int cntm=0;
		int cntp=0;
		for(int i=0;i<n;i++)
		{
		   if(s[i]=='+')
		   cntp++;
		   else
		   cntm++;

		   a[0][i]=cntm;
		   a[1][i]=cntp;
		}
		int res=0;
		int init=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]=='+')
			{
				res++;
				continue;
			}
			int dif=a[0][i]-a[1][i];
			if(init>=dif)
			{
				res++;
				continue;
			}
			res=res+(dif-init)*i+(dif-init+1);
			init=dif;
		}
		cout<<res<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		int n=s.size();
		int a[2][n];
		int cntm=0;
		int cntp=0;
		for(int i=0;i<n;i++)
		{
		   if(s[i]=='+')
		   cntp++;
		   else
		   cntm++;

		   a[0][i]=cntm;
		   a[1][i]=cntp;
		}
		int res=0;
		int init=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]=='+')
			{
				res++;
				continue;
			}
			if(a[1][i]>=a[0][i])
			{
				res++;
				continue;
			}
			int dif=a[0][i]-a[1][i];
			if(init>=dif)
			{
				res++;
				continue;
			}
			res=res+(dif-init)*i+(dif-init+1);
			init=dif;
		}
		cout<<res<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		int n=s.size();
		int a[2][n];
		int cntm=0;
		int cntp=0;
		for(int i=0;i<n;i++)
		{
		   if(s[i]=='+')
		   cntp++;
		   else
		   cntm++;

		   a[0][i]=cntm;
		   a[1][i]=cntp;
		}
		int left[n];
		for(int i=n-1;i>=0;i--)
		{
			if(i==n-1)
			left[i]=a[0][i]-a[1][i];
			else
			left[i]=max(left[i+1],a[0][i]-a[1][i]);
		}
		int res=0;
		int init=0;
		for(int i=0;i<n;i++)
		{
			if(left[i]<=0)
			{
				res++;
				continue;
			}
			if(left[i]<=init)
			{
				res++;
				continue;
			}
			int dif=a[0][i]-a[1][i];
			if(dif>init)
			{
				res=res+(dif-init+1);
				init=dif;
			}
			res=res+(left[i]-init);
		}
		cout<<res<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		ll n=s.size();
		ll a[2][n];
		ll cntm=0;
		ll cntp=0;
		for(int i=0;i<n;i++)
		{
		   if(s[i]=='+')
		   cntp++;
		   else
		   cntm++;

		   a[0][i]=cntm;
		   a[1][i]=cntp;
		}
		ll res=0;
		ll init=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]=='+')
			{
				res++;
				continue;
			}
			if((a[1][i]+init)>=a[0][i])
			{
				res++;
				continue;
			}
			ll dif=a[0][i]-a[1][i];
			res=res+(dif-init)*i+(dif-init+1);
			init=max(dif,init);
		}
		cout<<res<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		int n=s.size();
		int a[2][n];
		int cntm=0;
		int cntp=0;
		for(int i=0;i<n;i++)
		{
		   if(s[i]=='+')
		   cntp++;
		   else
		   cntm++;

		   a[0][i]=cntm;
		   a[1][i]=cntp;
		}
		int res=0;
		int iteration=0;
		for(int i=0;i<n;i++)
		{
			if(a[1][i]>=a[0][i])
			{
				res++;
				continue;
			}
			int dif=a[0][i]-a[1][i];
			if(dif<=iteration)
			{
				res++;
				continue;
			}
			res=res+(dif-iteration)*i+(dif-iteration+1);
			iteration=dif;
		}
		cout<<res<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		int n=s.size();
		int a[2][n];
		int cntm=0;
		int cntp=0;
		for(int i=0;i<n;i++)
		{
		   if(s[i]=='+')
		   cntp++;
		   else
		   cntm++;

		   a[0][i]=cntm;
		   a[1][i]=cntp;
		}
		int res=0;
		int init=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]=='+')
			{
				res++;
				continue;
			}
			if((a[1][i]+init)>=a[0][i])
			{
				res++;
				continue;
			}
			int dif=a[0][i]-a[1][i];
			res=res+(dif-init)*i+(dif-init+1);
			init=max(dif,init);
		}
		cout<<res<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		int n=s.size();
		int a[2][n];
		int cntm=0;
		int cntp=0;
		for(int i=0;i<n;i++)
		{
		   if(s[i]=='+')
		   cntp++;
		   else
		   cntm++;

		   a[0][i]=cntm;
		   a[1][i]=cntp;
		}
		int res=0;
		int init=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]=='+')
			{
				res++;
				continue;
			}
			int dif=a[0][i]-a[1][i];
			if(init>=dif)
			{
				res++;
				continue;
			}
			res=res+i+2;
			init++;
		}
		cout<<res<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
string s;
void solve(){
	cin >> s;
	int n = s.length();
	//cout << n << endl;
	ll ans = 0;
	int cnt = 0;
	int currt = -1;
	//cout << s << endl;
	for(int i = 0; i < n; i++){
		//cout << s[i] << endl;
		if(s[i] == '+')cnt++;
		else{cnt--;}
		//cout << i << " " << cnt << endl;
		if(cnt <= currt){
			//ans += i+1;
			currt--;
		    ans += (i+1);
        }
	}
	//cnt += abs(-1 * n - cnt)+1;
	if(true){
		ans += (n);
	}
	cout << ans << endl;
}
int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}

    return 0;

}


#include <bits/stdc++.h>
#define long long ll
using namespace std;
string s;
void solve(){
	cin >> s;
	int n = s.length();
	//cout << n << endl;
	ll ans = 0;
	int cnt = 0;
	int currt = -1;
	//cout << s << endl;
	for(int i = 0; i < n; i++){
		//cout << s[i] << endl;
		if(s[i] == '+')cnt++;
		else{cnt--;}
		//cout << i << " " << cnt << endl;
		if(cnt <= currt){
			//ans += i+1;
			currt--;
		    ans += (i+1);
        }
	}
	//cnt += abs(-1 * n - cnt)+1;
	if(true){
		ans += (n);
	}
	cout << ans << endl;
}
int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
string s;
void solve(){
	cin >> s;
	int n = s.length();
	//cout << n << endl;
	int ans = 0;
	int cnt = 0;
	//cout << s << endl;
	for(int i = 0; i < n; i++){
		//cout << s[i] << endl;
		if(s[i] == '+')cnt++;
		else{cnt--;}
		//cout << i << " " << cnt << endl;
		if(cnt < -1 * i){
			ans += i+1;
		}
	}
	//cnt += abs(-1 * n - cnt)+1;
	if(cnt <= 0){
		ans += (n);
	}
	cout << ans << endl;
}
int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
string s;
void solve(){
	cin >> s;
	int n = s.length();
	//cout << n << endl;
	int ans = 0;
	int cnt = 0;
	int currt = -1;
	//cout << s << endl;
	for(int i = 0; i < n; i++){
		//cout << s[i] << endl;
		if(s[i] == '+')cnt++;
		else{cnt--;}
		//cout << i << " " << cnt << endl;
		if(cnt <= currt){
			//ans += i+1;
			currt--;
		    ans += (i+1);
        }
	}
	//cnt += abs(-1 * n - cnt)+1;
	if(true)){
		ans += (n);
	}
	cout << ans << endl;
}
int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
string s;
void solve(){
	cin >> s;
	int n = s.length();
	//cout << n << endl;
	int ans = 0;
	int cnt = 0;
	//cout << s << endl;
	for(int i = 0; i < n; i++){
		//cout << s[i] << endl;
		if(s[i] == '+')cnt++;
		else{cnt--;}
		//cout << i << " " << cnt << endl;
		if(cnt < -1 * i){
			ans += i+1;
		}
	}
	//cnt += abs(-1 * n - cnt)+1;
	if(true){
		ans += (n);
	}
	cout << ans << endl;
}
int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
string s;
void solve(){
	cin >> s;
	int n = s.length();
	//cout << n << endl;
	int ans = 0;
	int cnt = 0;
	int currt = -1;
	//cout << s << endl;
	for(int i = 0; i < n; i++){
		//cout << s[i] << endl;
		if(s[i] == '+')cnt++;
		else{cnt--;}
		//cout << i << " " << cnt << endl;
		if(cnt <= currt){
			//ans += i+1;
			currt--;
		    ans += (i+1);
        }
	}
	//cnt += abs(-1 * n - cnt)+1;
	if(cnt <= 0){
		ans += (n);
	}
	cout << ans << endl;
}
int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}

    return 0;

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
string s;
void solve(){
	cin >> s;
	int n = s.length();
	//cout << n << endl;
	ll ans = 0;
	int cnt = 0;
	int currt = -1;
	//cout << s << endl;
	for(int i = 0; i < n; i++){
		//cout << s[i] << endl;
		if(s[i] == '+')cnt++;
		else{cnt--;}
		//cout << i << " " << cnt << endl;
		if(cnt <= currt){
			//ans += i+1;
			currt--;
		    ans += (i+1);
        }
	}
	//cnt += abs(-1 * n - cnt)+1;
	if(true){
		ans += (n);
	}
	cout << ans << endl;
}
int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
string s;
void solve(){
	cin >> s;
	int n = s.length();
	//cout << n << endl;
	int ans = 0;
	int cnt = 0;
	int currt = -1;
	//cout << s << endl;
	for(int i = 0; i < n; i++){
		//cout << s[i] << endl;
		if(s[i] == '+')cnt++;
		else{cnt--;}
		//cout << i << " " << cnt << endl;
		if(cnt <= currt){
			//ans += i+1;
			currt--;
		    ans += (i+1);
        }
	}
	//cnt += abs(-1 * n - cnt)+1;
	if(true){
		ans += (n);
	}
	cout << ans << endl;
}
int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}

    return 0;

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pb push_back
#define Map map<ll, ll>
#define Pair pair<ll, ll>
#define Set set<ll>
#define Sort sort(v.begin(), v.end())

int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		string s;
		cin >> s;

		vector<ll> v;

		ll sum = 0;
		ll maxnum = INT_MIN;

		for(int i = 0; i < s.size(); i++)
		{
			if(s[i] == '-')
				sum++;
			else
				sum--;
			v.pb(sum);

			maxnum = max(maxnum, sum);
		}

		//~ for(auto i : v)
			//~ cout << i << " ";
		//~ cout << '\n';

		//~ cout << "max " << maxnum << '\n';

		ll num = 0;
		ll ans = 0;

		while(true)
		{

			if(num >= maxnum)
			{
				ans += v.size();
				break;
			}
			for(int i = 0; i < v.size(); i++)
			{
				if(num < v[i])
				{
					ans += i;
					ans++;
					break;
				}

			}
			//~ cout << ans << '\n';

			num++;
		}

		cout << ans << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pb push_back
#define Map map<ll, ll>
#define Pair pair<ll, ll>
#define Set set<ll>
#define Sort sort(v.begin(), v.end())

int main()
{
	int t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;
		Map mp;

		ll ans = 0;

		ll sum = 0;
		ll maxnum = INT_MIN;
		bool flag = true;

		for(int i = 0; i < s.size(); i++)
		{
			if(s[i] == '-')
				sum++;
			else
				sum--;

			if(sum >= 0)
			{
				if(mp[sum] == 0)
					mp[sum] = i + 2;
			}

			maxnum = max(maxnum, sum);
		}

		if(s[0] == '-')
		{
			ans += 1;
			mp[0] = 0;
		}

		ll num = 0;

		while(true)
		{

			if(num >= maxnum)
			{
				ans += s.size();
				break;
			}

			if(num < maxnum)
			{
				ans += mp[num];

			}

			num++;
		}

		cout << ans << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pb push_back
#define Map map<ll, ll>
#define Pair pair<ll, ll>
#define Set set<ll>
#define Sort sort(v.begin(), v.end())

int main()
{
	int t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;
		Map mp;

		ll ans = 0;

		ll sum = 0;
		ll maxnum = INT_MIN;

		for(int i = 0; i < s.size(); i++)
		{
			if(s[i] == '-')
				sum++;
			else
				sum--;

			if(sum >= 0)
			{
				if(mp[sum] == 0)
					mp[sum] = i + 1;
			}

			maxnum = max(maxnum, sum);
		}

		ll num = 0;

		while(true)
		{

			if(num >= maxnum)
			{
				ans += s.size();
				break;
			}

			if(num < maxnum)
			{
				ans += mp[num + 1];

			}

			num++;
		}

		cout << ans << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pb push_back
#define Map map<ll, ll>
#define Pair pair<ll, ll>
#define Set set<ll>
#define Sort sort(v.begin(), v.end())

int main()
{
	int t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;
		Map mp;

		ll ans = 0;

		ll sum = 0;
		ll maxnum = INT_MIN;
		bool flag = true;

		for(int i = 0; i < s.size(); i++)
		{
			if(s[i] == '-')
				sum++;
			else
				sum--;
			if(sum >= 0)
			{
				if(mp[sum] == 0)
				{
					mp[sum] = i + 1;
				}
			}

			maxnum = max(maxnum, sum);
		}

		ll num = 0;

		while(true)
		{

			if(num >= maxnum)
			{
				ans += s.size();
				break;
			}

			if(num < maxnum)
			{
				ans += mp[num];
				ans++;
			}

			num++;
		}

		cout << ans << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pb push_back
#define Map map<ll, ll>
#define Pair pair<ll, ll>
#define Set set<ll>
#define Sort sort(v.begin(), v.end())

int main()
{
	int t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;
		Map mp;

		vector<ll> v;

		ll sum = 0;
		ll maxnum = INT_MIN;

		for(int i = 0; i < s.size(); i++)
		{
			if(s[i] == '-')
				sum++;
			else
				sum--;
			v.pb(sum);

			if(mp[sum] == 0)
				mp[sum] = i + 1;

			maxnum = max(maxnum, sum);
		}

		//~ for(auto i : v)
			//~ cout << i << " ";
		//~ cout << '\n';

		//~ cout << "max " << maxnum << '\n';

		ll num = 0;
		ll ans = 0;

		while(true)
		{

			if(num >= maxnum)
			{
				ans += v.size();
				break;
			}

			ans += mp[num];
			ans++;
			//~ cout << "ans" << ans << '\n';

			num++;
		}

		cout << ans << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pb push_back
#define Map map<ll, ll>
#define Pair pair<ll, ll>
#define Set set<ll>
#define Sort sort(v.begin(), v.end())

int main()
{
	int t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;
		Map mp;

		ll ans = 0;

		ll sum = 0;
		ll maxnum = INT_MIN;
		bool flag = true;

		for(int i = 0; i < s.size(); i++)
		{
			if(s[i] == '-')
				sum++;
			else
				sum--;

			if(mp[sum] == 0)
				mp[sum] = i + 1;
			if(sum > 0 && flag)
			{
				ans += i + 1;
				flag = false;
			}

			maxnum = max(maxnum, sum);
		}

		ll num = 1;

		while(true)
		{

			if(num >= maxnum)
			{
				ans += s.size();
				break;
			}

			if(num < maxnum)
			{
				ans += mp[num];
				ans++;
			}

			num++;
		}

		cout << ans << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pb push_back
#define Map map<ll, ll>
#define Pair pair<ll, ll>
#define Set set<ll>
#define Sort sort(v.begin(), v.end())

int main()
{
	int t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;
		Map mp;

		ll ans = 0;

		ll sum = 0;
		ll maxnum = INT_MIN;

		for(int i = 0; i < s.size(); i++)
		{
			if(s[i] == '-')
				sum++;
			else
				sum--;

			if(sum >= 0)
			{
				if(mp[sum] == 0)
					mp[sum] = i + 2;
			}

			maxnum = max(maxnum, sum);
		}

		if(s[0] == '-')
		{
			ans += 1;
			mp[0] = 0;
		}

		ll num = 0;

		while(true)
		{

			if(num >= maxnum)
			{
				ans += s.size();
				break;
			}

			if(num < maxnum)
			{
				ans += mp[num];

			}

			num++;
		}

		cout << ans << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pb push_back
#define Map map<ll, ll>
#define Pair pair<ll, ll>
#define Set set<ll>
#define Sort sort(v.begin(), v.end())

int main()
{
	int t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;
		Map mp;

		ll ans = 0;

		ll sum = 0;
		ll maxnum = INT_MIN;
		bool flag = true;

		for(int i = 0; i < s.size(); i++)
		{
			if(s[i] == '-')
				sum++;
			else
				sum--;

			if(mp[sum] == 0)
			{
				if(sum > 0)
					mp[sum] = i + 1;
			}
			if(sum > 0 && flag)
			{
				ans += i + 1;
				flag = false;
			}

			maxnum = max(maxnum, sum);
		}

		ll num = 1;

		while(true)
		{

			if(num >= maxnum)
			{
				ans += s.size();
				break;
			}

			if(num < maxnum)
			{
				ans += mp[num];
				ans++;
			}

			num++;
		}

		cout << ans << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pb push_back
#define Map map<ll, ll>
#define Pair pair<ll, ll>
#define Set set<ll>
#define Sort sort(v.begin(), v.end())

int main()
{
	int t;
	int o;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;
		Map mp;

		ll ans = 0;

		ll sum = 0;
		ll maxnum = INT_MIN;

		for(int i = 0; i < s.size(); i++)
		{
			if(s[i] == '-')
				sum++;
			else
				sum--;

			if(sum >= 0)
			{
				if(mp[sum] == 0)
					mp[sum] = i + 1;
			}

			maxnum = max(maxnum, sum);
		}

		ll num = 0;

		while(true)
		{

			if(num >= maxnum)
			{
				ans += s.size();
				break;
			}

			if(num < maxnum)
			{
				ans += mp[num + 1];

			}

			num++;
		}

		cout << ans << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pb push_back
#define Map map<ll, ll>
#define Pair pair<ll, ll>
#define Set set<ll>
#define Sort sort(v.begin(), v.end())

int main()
{
	int t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;
		Map mp;

		vector<ll> v;

		ll ans = 0;

		ll sum = 0;
		ll maxnum = INT_MIN;
		bool flag = true;

		for(int i = 0; i < s.size(); i++)
		{
			if(s[i] == '-')
				sum++;
			else
				sum--;
			v.pb(sum);

			if(mp[sum] == 0)
				mp[sum] = i + 1;
			if(sum > 0 && flag)
			{
				ans += i + 1;
				flag = false;
			}

			maxnum = max(maxnum, sum);
		}

		//~ for(auto i : v)
			//~ cout << i << " ";
		//~ cout << '\n';

		//~ cout << "max " << maxnum << '\n';

		ll num = 1;

		while(true)
		{

			if(num >= maxnum)
			{
				ans += s.size();
				break;
			}

			ans += mp[num];
			ans++;
			//~ cout << "ans" << ans << '\n';

			num++;
		}

		cout << ans << '\n';
	}
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define PI 3.1415926535
#define ff              first
#define ss              second
#define int             long long int
#define float           double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define from(i,n)       for(int i=0;i<(int)n;i++)
#define from_j(i,j,n)   for(int i=j;i<(int)n;i++)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
    c_p_c();
    w(t){
        string s;
        cin>>s;
        int res=0,l=s.size();
        from(i,s.size())
        if(s[i]=='+')
        s[i]=1;
        else s[i]=-1;
        for(int init=0;init<=l;init++)
        {
            int cur=init;
            int ok=1;
            for(int i=0;i<l;i++)
            {
                res++;
                cur+=s[i];
                if(cur<0)
                {
                    ok=0;
                    break;
                }
            }
            if(ok)
            break;
        }
        cout<<res<<endl;

/*res = 0
for init = 0 to inf
    cur = init
    ok = true
    for i = 1 to |s|
        res = res + 1
        if s[i] == '+'
            cur = cur + 1
        else
            cur = cur - 1
        if cur < 0
            ok = false
            break
    if ok
        break
        */

    }
    return 0;
}