You are given a string $s$ consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode: 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



Note that the $inf$ denotes infinity, and the characters of the string are numbered from $1$ to $|s|$.

You have to calculate the value of the $res$ after the process ends.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.

The only lines of each test case contains string $s$ ($1 \le |s| \le 10^6$) consisting only of characters + and -.

It's guaranteed that sum of $|s|$ over all test cases doesn't exceed $10^6$.


-----Output-----

For each test case print one integer — the value of the $res$ after the process ends.


-----Example-----
Input
3
--+-
---
++--+-

Output
7
9
6

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
def checker(s):
	result = len(s)
	(cur, mx) = (0, 0)
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if mx > cur:
			mx = cur
			result += i + 1
	return result
for _ in range(int(input())):
	t = input()
	print(checker(t))


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heappushpop, heapreplace

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['NET', 'DA']
test_case = ii()
while test_case:
	test_case -= 1
	a = lsi()
	p = [len(a)]
	x = 0
	c = 1
	for i in range(len(a)):
		if a[i] == '-':
			x += 1
			if x == c:
				c += 1
				p.append(i + 1)
		else:
			x -= 1
	print(sum(p))


t = int(input())
for _ in range(t):
	s = input()
	cnt = dict()
	c = 0
	for i in range(len(s)):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
		if c not in cnt.keys():
			cnt[c] = i
	res = 0
	for init in range(-min(cnt.keys())):
		res += cnt[-init - 1] + 1
	res += len(s)
	print(res)


t = int(input())
for _ in range(t):
	s = input()
	ans = len(s)
	cur = 0
	pos = 0
	min_d = 0
	for s_i in s:
		pos += 1
		if s_i == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0 and cur < min_d:
			ans += pos
		min_d = min(min_d, cur)
	print(ans)


import sys
from collections import defaultdict as dd
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	arr = list(map(str, input().strip()))
	co = 0
	cz = 0
	mini = 99999999999
	ans = 0
	summ = 0
	l = [-1] * (len(arr) + 1)
	ind = 0
	for i in arr:
		ind += 1
		if i == '+':
			summ += 1
		else:
			summ -= 1
		if summ < 0 and l[summ * -1] == -1:
			l[summ * -1] = ind
			ans += ind
		mini = min(mini, summ)
	print(ans + len(arr))


t = int(input())
for _ in range(t):
	s = input()
	s = list(str(s))
	num = 0
	res = 1
	Total = 0
	count = -1
	z = []
	for i in range(len(s)):
		if s[i] == '+':
			num += 1
		else:
			num -= 1
		z.append(num)
	for r in z:
		if r == count:
			Total += res
			count -= 1
		res += 1
	print(Total + len(s))


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().strip()
	n = len(s)
	a = [0] * n
	for i in range(n):
		if s[i] == '-':
			a[i] -= 1
		else:
			a[i] += 1
		if i > 0:
			a[i] += a[i - 1]
	ans = n
	mn = 0
	for i in range(n):
		if a[i] < mn:
			mn = a[i]
			ans += i + 1
	print(ans)


import sys
import math
read = sys.stdin.buffer.read
readlines = sys.stdin.buffer.readlines
t = int(input())
for case in range(t):
	s = input()
	n = len(s)
	ans = 0
	cnt = [0] * (1 + n)
	cum = 0
	for i in range(n):
		if s[i] == '-':
			cum += 1
		else:
			cum -= 1
		if cum > 0 and cnt[cum] == 0:
			ans += i + 1
			cnt[cum] = i + 1
	ans += i + 1
	print(ans)


for t in range(int(input())):
	s = input()
	curlist = []
	cur = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		curlist.append(cur)
	leng = len(curlist)
	res = 0
	init = 1
	for j in range(leng):
		if curlist[j] == -init:
			res += j + 1
			init += 1
	print(res + leng)


t = int(input())
for _ in range(t):
	s = input()
	ans = len(s)
	count = 0
	for i in range(len(s)):
		if s[i] == '+':
			count += 1
		else:
			count -= 1
		if count < 0:
			count += 1
			ans += i + 1
	print(ans)


from sys import stdin, stdout
import math
t = int(stdin.readline())
for _ in range(t):
	s = stdin.readline().strip()
	cur = 0
	ans = len(s)
	(mini, cur_min) = (-1, float('inf'))
	for i in range(len(s)):
		x = s[i]
		if x == '-':
			cur -= 1
			if cur < 0 and cur < cur_min:
				cur_min = cur
				ans += i + 1
		else:
			cur += 1
	print(ans)


rw = int(input())
for ewq in range(rw):
	s = input()
	n = len(s)
	sp = s.count('+')
	sm = s.count('-')
	v = [0] * n
	for i in range(n):
		if s[i] == '+':
			v[i] = v[i - 1] + 1
		else:
			v[i] = v[i - 1] - 1
	init = min(v)
	if init >= 0:
		print(n)
		continue
	init = abs(init)
	j = 0
	u = [0] * init
	for i in range(init):
		while i + v[j] >= 0:
			j += 1
		u[i] = j
	print(n + sum(u) + init)


t = int(input())
for i in range(t):
	string = input()
	res = 0
	init = 0
	cur = init
	for i in range(len(string)):
		res = res + 1
		if string[i] == '+':
			cur = cur + 1
		else:
			cur = cur - 1
		if cur < 0:
			cur = 0
			res += i + 1
	print(res)


for _ in range(int(input())):
	s = input()
	n = len(s)
	data = [0] * n
	for i in range(n):
		if s[i] == '+':
			data[i] = 1
		else:
			data[i] = -1
	for i in range(1, n):
		data[i] += data[i - 1]
	data = [-data[i] for i in range(n)]
	for i in range(1, n):
		data[i] = max(data[i], data[i - 1])
	res = 0
	val = 0
	id = 0
	while id < n:
		if data[id] > val:
			res += id + 1
			val += 1
		else:
			id += 1
	res += id
	print(res)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	l = []
	cur = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			cur = 0
			if len(l) > 0:
				l.append(l[-1] + (i + 1))
			else:
				l.append(i + 1)
	if len(l) > 0:
		print(len(s) + l[-1])
	else:
		print(len(s))


t = int(input())
for _ in range(t):
	s = input()
	ans = 0
	(max_v, min_v) = (9223372036854775807, -9223372036854775807)
	for i in range(len(s)):
		if s[i] == '+':
			ans += 1
		else:
			ans -= 1
		max_v = max(max_v, ans)
		min_v = min(min_v, ans)
	max_i = max(abs(min_v), abs(max_v))
	(res, cur) = (0, 0)
	for j in range(len(s)):
		if s[j] == '-':
			cur -= 1
		else:
			cur += 1
		if cur < 0:
			res += j + 1
			cur += 1
		if j == len(s) - 1:
			res += len(s)
	print(res)


import math
import bisect
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
T = inp()
for t in range(T):
	s = insr()
	res = 0
	c = 0
	init = 0
	for i in range(len(s)):
		if s[i] == '-':
			c -= 1
		else:
			c += 1
		if c + init < 0:
			init += 1
			res += i + 1
	print(res + len(s))


import math
t = int(input())
for testcase in range(t):
	A = input()
	lastValue = 0
	answer = 0
	for i in range(len(A)):
		if A[i] == '-':
			if lastValue - 1 < 0:
				answer += i + 1
			lastValue = lastValue - 1
		else:
			lastValue = max(lastValue + 1, 1)
	answer += len(A)
	print(answer)


for _ in range(int(input())):
	r = input()
	s = out = 0
	for i in range(len(r)):
		if r[i] == '+':
			s += 1
		else:
			s -= 1
		if s < 0:
			out += i + 1
			s = 0
	print(out + len(r))


from math import *
t = int(input())
while t > 0:
	s = input()
	f = []
	n = len(s)
	for i in range(n):
		if s[i] == '+':
			f.append(0)
		else:
			f.append(-1)
	if s[0] == '+':
		f[0] = 1
	for i in range(1, n):
		if s[i] == '+':
			if f[i - 1] < 0:
				f[i] = 1
			else:
				f[i] = 1 + f[i - 1]
		else:
			f[i] = f[i - 1] - 1
	ans = n
	for i in range(n):
		if f[i] < 0:
			ans = ans + (i + 1)
	print(ans)
	t -= 1


t = int(input())
while t:
	s = input()
	cur = 0
	res = 0
	curr = -1
	for i in range(len(s)):
		if s[i] == '-':
			cur -= 1
		else:
			cur += 1
		if cur == curr:
			res += i + 1
			curr = curr - 1
	res += len(s)
	print(res)
	t -= 1


n = int(input())
for j in range(n):
	s = input()
	res = len(s)
	sol = d = 0
	for i in range(len(s)):
		if s[i] == '+':
			sol += 1
		else:
			sol -= 1
		if sol + d < 0:
			res += i + 1
			d += 1
	print(res)


import sys, math, cmath, time
start_time = time.time()

def solve():
	s = insr()
	q = 0
	w = 0
	qw = 0
	qq = []
	for i in range(len(s)):
		if s[i] == '+':
			q = q + 1
		else:
			w = w + 1
		if q < w:
			qq.append([i, q - w])
	c = 0
	qw = 0
	for i in range(len(qq)):
		if qw + qq[i][1] < 0:
			c = c + qq[i][0] + 1
			qw = qw + 1
	print(c + len(s))

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = (q[a[i] - 1], 1)
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = (q[ord(a[i]) - 97], 1)
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


for i in range(int(input())):
	s = input()
	a = 0
	b = [0] * len(s)
	for i in range(len(s)):
		if s[i] == '+':
			a = a + 1
			b[i] = a
		else:
			a = a - 1
			b[i] = a
	res = 0
	min = 0
	minp = 0
	for i in range(len(s)):
		if (b[i] < 0) & (b[i] < min):
			minp = min
			min = b[i]
			res = res + (minp - min) * (i + 1)
	print(res + len(s))


for _ in ' ' * int(input()):
	a = input()
	res = len(a)
	(k, f) = (0, 0)
	for i in range(len(a)):
		k += -1 if a[i] == '-' else 1
		if k < f:
			res += i + 1
			f = k
	print(res)


def main():
	for _ in range(int(input())):
		a = list(input())
		l = []
		(p, m) = (0, 0)
		for i in range(len(a)):
			if a[i] == '-':
				m -= 1
			if a[i] == '+':
				m += 1
			l.append((m, i))
		(k, mini, xyz) = (0, 0, [])
		for i in range(len(a)):
			if l[i][0] < 0:
				if mini > l[i][0]:
					k += l[i][1] + 1
					mini = l[i][0]
		p1 = min(l)
		p = p1[1]
		print(k + len(a))
main()


from fractions import Fraction
import bisect
import os
import io
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for _ in range(t):
	s = input()
	ans = 0
	myplus = 0
	for i in range(len(s)):
		if s[i] == '-':
			if myplus != 0:
				myplus -= 1
			else:
				ans += i + 1
		else:
			myplus += 1
	print(ans + len(s))


import sys
input = sys.stdin.readline

def cum_sum(lst):
	cums = [0] * (len(lst) + 1)
	cums[1] = lst[0]
	for i in range(2, len(lst) + 1):
		cums[i] = cums[i - 1] + lst[i - 1]
	return cums
import bisect
t = int(input())
for _ in range(t):
	s = list(input())
	nums = []
	for i in range(len(s) - 1):
		if s[i] == '-':
			nums.append(-1)
		else:
			nums.append(1)
	cum_nums = cum_sum(nums)
	nim = min(cum_nums)
	if nim == 0:
		print(len(s) - 1)
		continue
	cnt = []
	now_nax = 0
	for i in range(1, len(cum_nums)):
		if cum_nums[i] < now_nax:
			cnt.append(-cum_nums[i])
			now_nax = cum_nums[i]
		else:
			cnt.append(-now_nax)
	ans = 0
	cnt.append(int(10000000000.0))
	cnt.insert(0, -1)
	for i in range(-now_nax + 1):
		u = bisect.bisect_right(cnt, i)
		if u == len(cnt) - 1:
			u -= 1
		ans += u
	print(ans)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for ii in range(int(input())):
	s = input()
	n = len(s)
	vis = defaultdict(int)
	cur = 0
	ans = 0
	for i in range(n):
		if s[i] == '+':
			cur += 1
		if s[i] == '-':
			cur -= 1
		if cur < 0 and cur not in vis:
			vis[cur] = 1
			ans += i + 1
	ans += n
	print(ans)


n = int(input())
a = []
for z in range(n):
	s = input()
	l = len(s)
	res = 0
	cur = 0
	for i in range(l):
		res += 1
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			cur = 0
			res += i + 1
	a.append(res)
for i in range(n):
	print(a[i])


t = int(input())
for _ in range(0, t):
	s = '0' + input()
	dic = dict()
	cur = 0
	for i in range(1, len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur not in dic:
			dic[cur] = i
	(i, res) = (0, 0)
	while True:
		want = -(i + 1)
		if want in dic:
			res += dic[want]
		else:
			res += len(s) - 1
			break
		i += 1
	print(res)


import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
input = lambda : sys.stdin.readline()

def solve():
	for _ in range(int(sys.stdin.readline())):
		s = sys.stdin.readline().replace('\n', '')
		a = []
		n = len(s)
		for i in s:
			if i == '+':
				a.append(1)
			else:
				a.append(-1)
		a = list(accumulate(a))
		ex = defaultdict(lambda : 0)
		for i in range(len(a)):
			if a[i] not in ex:
				ex[a[i]] = i + 1
		i = 0
		ans = 0
		for i in range(-min(a)):
			ans += ex[-(i + 1)]
		print(ans + n)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


import math
from decimal import *
for _ in range(int(input())):
	s = str(input())
	ans = 0
	cnt = 0
	p = 1
	while p <= len(s):
		if s[p - 1] == '+':
			cnt = max(1, cnt + 1)
		elif s[p - 1] == '-':
			cnt = max(-1, cnt - 1)
		if cnt < 0:
			ans += p
		p += 1
	if cnt >= -1:
		ans += len(s)
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	hashMap = {}
	bal = 0
	for i in range(len(s)):
		if s[i] == '+':
			bal += 1
		else:
			bal -= 1
		if bal < 0 and bal not in hashMap.keys():
			hashMap[bal] = i + 1
	res = len(s)
	for i in range(-1, -len(s) - 1, -1):
		if i in hashMap.keys():
			res += hashMap[i]
	print(res)


for _ in range(int(input())):
	s = list(input())
	m = 0
	n = len(s)
	ans = 0
	p = 0
	b = []
	for i in range(n):
		if s[i] == '-':
			m += 1
		else:
			m -= 1
		if m > p:
			b.append(i)
			p = m
	for i in range(len(b)):
		ans += b[i] + 1
	ans += n
	print(ans)


from collections import defaultdict
for i in range(int(input())):
	s = input()
	m = 0
	p = 0
	dic = defaultdict(lambda : None)
	for i in range(len(s)):
		if s[i] == '-':
			m += 1
		else:
			p += 1
		if m - p > 0:
			if dic[m - p] == None:
				dic[m - p] = i
	ans = 0
	for i in range(1, 10 ** 9):
		if dic[i] != None:
			ans += dic[i] + 1
		else:
			ans += len(s)
			break
	print(ans)


ll = lambda : list(map(int, input().split()))
st = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
from collections import *
from math import *
for _ in range(ii()):
	s = st()
	n = len(s)
	res = 0
	t = []
	for i in range(n):
		if s[i] == '+':
			res += 1
		else:
			res -= 1
		if res < 0:
			t.append([res, i + 1])
	if len(t) == 0:
		print(n)
		continue
	t.sort()
	m = t[0][1]
	t.sort(key=lambda x: x[1])
	ans = 0
	u = 0
	for i in range(len(t)):
		if abs(t[i][0]) > u:
			ans += (abs(t[i][0]) - u) * t[i][1]
			u = abs(t[i][0])
	ans += n
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	p = 0
	m = 0
	dict = {}
	for i in range(len(s)):
		if s[i] == '+':
			p += 1
		if s[i] == '-':
			m += 1
		if dict.get(p - m) is None:
			dict[p - m] = i + 1
	ans = 0
	for i in range(0, len(s) + 1):
		if dict.get(-(i + 1)) is None:
			ans += len(s)
			break
		ans += dict[-(i + 1)]
	print(ans)


from sys import stdin
for _ in range(int(stdin.readline())):
	s = stdin.readline().strip()
	su = 0
	val = -1
	cou = 0
	for (ind, i) in enumerate(s):
		if i == '+':
			cou += 1
		else:
			cou -= 1
		if cou == val:
			su += ind + 1
			val -= 1
	su += len(s)
	print(su)


for i in range(int(input())):
	s = input()
	count = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '-':
			if count == 0:
				ans += i + 2
			else:
				count -= 1
				ans += 1
		else:
			count += 1
			ans += 1
	print(ans)


for ikop in range(int(input())):
	l = input()
	pos = 0
	ans = 0
	pon = 0
	ear = 0
	for i in range(len(l)):
		if l[i] == '+':
			pos += 1
		elif pos > 0:
			pos -= 1
			pon += 2
		else:
			ear += 1
			ear += pon
			pon = 0
			ans += ear
	print(ans + ear + pos + pon)


for _ in range(int(input())):
	s = input()
	pref = []
	p = 0
	for elem in s:
		if elem == '-':
			p -= 1
		else:
			p += 1
		pref.append(p)
	ans = 0
	c = -1
	for i in range(len(s)):
		if pref[i] == c:
			ans += i + 1
			c -= 1
		if i == len(s) - 1 and pref[i] != c:
			ans += len(s)
	print(ans)


for _ in range(int(input())):
	lo = curr = res = 0
	s = input()
	for i in range(len(s)):
		curr += 1 if s[i] == '+' else -1
		if curr < lo:
			res += i + 1
			lo = curr
	print(res + len(s))


a = input()
for x in range(int(a)):
	b = input()
	ans = 0
	cur = 0
	tag = 0
	for i in range(len(b)):
		if b[i] == '+':
			cur = cur + 1
		else:
			cur = cur - 1
		if cur < tag:
			ans += i + 1
			tag = cur
	ans += len(b)
	print(ans)


for i in range(int(input())):
	s = input()
	l = [0] * len(s)
	su = 0
	sum = 0
	var = 10 ** 6
	for i in range(len(s)):
		if s[i] == '-':
			su -= 1
		else:
			su += 1
		l[i] = su
		if su < 0 and su < var:
			var = su
			sum += i + 1
	sum += len(s)
	print(sum)


for _ in range(int(input())):
	s = input()
	curr = 0
	balance = 0
	for i in s:
		if i == '+':
			curr += 1
		else:
			curr -= 1
			if curr < balance:
				balance = curr
	res = len(s)
	if balance <= 0:
		mxm = -balance
		amount = mxm
		array = [True] * amount
		curr = 0
		res = len(s)
		for i in s:
			res += amount
			if i == '+':
				curr += 1
			else:
				curr -= 1
				if curr < 0:
					j = abs(curr) - 1
					if j < mxm:
						if array[j]:
							array[j] = False
							amount -= 1
			if amount < 1:
				break
	print(res)


for i in range(int(input())):
	s = input()
	q = len(s)
	t = 1
	k = 0
	for j in s:
		if j == '+':
			k += 1
		elif k <= 0:
			q += t
		else:
			k -= 1
		t += 1
	print(q)


t = int(input())
for i in range(t):
	res = 0
	s = list(input())
	k = s.count('-')
	p = 0
	if k == len(s):
		res += k + k * (k + 1) // 2
	else:
		for j in range(len(s)):
			if s[j] == '-':
				if p == 0:
					res += j + 1
				else:
					p -= 1
			else:
				p += 1
		res += len(s)
	print(res)


for _ in range(int(input())):
	s = input()
	n = len(s)
	arr = [0 for i in range(n)]
	tmp = 0
	m = 9999999
	ans = n
	for i in range(n):
		if s[i] == '+':
			arr[i] = tmp + 1
		else:
			arr[i] = tmp - 1
		tmp = arr[i]
		if tmp < 0 and tmp < m:
			m = tmp
			ans += i + 1
	print(ans)


for _ in range(int(input())):
	s = input()
	net = 0
	dp = [0]
	init = [0]
	x = 0
	i = 0
	for c in s:
		a = dp[-1]
		x += 1
		if c == '+':
			net += 1
			a += 1
		else:
			net -= 1
			a -= 1
		if i + a < 0:
			init.append(init[-1] + x)
			i += 1
		dp.append(a)
	print(init[-1] + len(s))


def answer(s):
	dp = [0] * len(s)
	for i in range(len(s)):
		if s[i] == '-':
			dp[i] = dp[i - 1] - 1
		else:
			dp[i] = dp[i - 1] + 1
	mini = 0
	res = 0
	for i in range(len(s)):
		if dp[i] < mini:
			res += i + 1
			mini = dp[i]
	return res + len(s)
t = int(input())
for i in range(t):
	s = input()
	print(answer(s))


__MULTITEST = True

def solve():
	s = str(input())
	n = len(s)
	d = [0] * (n + 1)
	for i in range(1, n + 1):
		if s[i - 1] == '+':
			d[i] = d[i - 1] + 1
		else:
			d[i] = d[i - 1] - 1
	ans = 0
	neomin = 0
	for i in range(1, n + 1):
		if neomin > d[i]:
			neomin = d[i]
			ans += i
	ans += n
	print(ans)
t = int(input()) if __MULTITEST else 1
for tt in range(t):
	solve()


for _ in range(int(input())):
	s = input()
	(cur, temp, res) = (0, 0, len(s))
	for i in range(len(s)):
		cur += 1 if s[i] == '+' else -1
		if cur < temp:
			temp = cur
			res += i + 1
	print(res)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	S = input()
	v = 0
	ans = 0
	lowest = 0
	for (i, c) in enumerate(S):
		if c == '+':
			v += 1
		else:
			v -= 1
			if v < lowest:
				lowest = v
				ans += i + 1
	ans += len(S)
	print(ans)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


for _ in range(int(input())):
	a = input()
	cur = 0
	init = 0
	res = 0
	(n, p) = (0, 0)
	for i in a:
		if i == '-':
			n += 1
		else:
			p += 1
	maxi = n
	for (i, v) in enumerate(a):
		if v == '-':
			cur -= 1
			if cur < 0:
				res += i + 1
				cur = 0
		else:
			cur += 1
	print(res + len(a))


for _ in range(int(input())):
	s = input()
	abtk = 0
	ans = 0
	a = 0
	for i in s:
		if i == '-':
			if abtk == 0:
				ans += a + 1
			else:
				abtk -= 1
		else:
			abtk += 1
		a += 1
	ans += len(s)
	print(ans)


for _ in range(int(input())):
	s = input()
	pr = [0]
	for i in s:
		if i == '+':
			pr.append(pr[-1] + 1)
		else:
			pr.append(pr[-1] - 1)
	minv = 0
	ans = len(s)
	for i in range(len(pr)):
		if pr[i] < minv:
			ans += i
			minv = pr[i]
	print(ans)


import os, io
from sys import stdout
import collections
import random
import math
from operator import itemgetter
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import Counter
import heapq

def primes(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [i for i in range(3, n, 2) if sieve[i]]

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def divisors(n):
	i = 1
	result = []
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
		i += 1
	return result
t = int(input())
for _ in range(t):
	s = input().decode('utf-8').strip()
	l = []
	v = 0
	for c in s:
		if c == '+':
			v += 1
		else:
			v -= 1
		l.append(v)
	r = 0
	inc = 1
	for (index, v) in enumerate(l):
		if v < 0 and -v >= inc:
			inc += 1
			r += index + 1
	r += len(s)
	print(r)


t = int(input())
while t:
	t -= 1
	s = input()
	ans = 0
	curr = 0
	min_curr = 0
	for i in range(len(s)):
		if s[i] == '-':
			curr -= 1
		else:
			curr += 1
		if curr < 0 and curr < min_curr:
			min_curr = curr
			ans += i + 1
	ans += len(s)
	print(ans)


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	s = input().strip()
	ans = []
	cur = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			cur += 1
			ans.append(i + 1)
	print(sum(ans) + len(s))


tt = int(input())
for loop in range(tt):
	s = input()
	lis = [-1]
	for i in s:
		if i == '-':
			lis.append(lis[-1] + 1)
		else:
			lis.append(lis[-1] - 1)
	now = -1
	ans = 0
	for i in range(1, len(lis)):
		if lis[i] > now:
			ans += i * (lis[i] - now)
			now = lis[i]
	print(ans + len(s))


def res(s):
	pos = 0
	neg = 0
	count = 0
	ret = 0
	ind = 0
	for c in s:
		ind += 1
		if c == '+':
			pos += 1
		else:
			neg += 1
		count += 1
		if neg > pos:
			ret += count
			pos += 1
		if ind == len(s) and neg <= pos:
			ret += count
	return ret
for _ in range(int(input())):
	print(res(input()))


def parse(string, res):
	cur = 0
	for i in range(0, len(string)):
		if s[i] == '+':
			cur += 1
		elif s[i] == '-':
			cur -= 1
		if cur < 0:
			res += i + 1
			cur = 0
	return res
t = int(input())
for i in range(0, t):
	s = input()
	res = parse(s, len(s))
	print(res)


for _ in range(int(input())):
	s = input()
	n = len(s)
	answer = n
	t = 0
	for i in range(n):
		if s[i] == '-':
			if t > 0:
				t -= 1
			else:
				answer += i + 1
		else:
			t += 1
	print(answer)


t = int(input())
while t != 0:
	n = list(input())
	diff = list()
	neg = 0
	pos = 0
	for i in range(len(n)):
		if n[i] == '-':
			neg += 1
		else:
			pos += 1
		diff.append(neg - pos)
	i = 0
	sec = list()
	maxi = -pow(10, 9)
	while i < len(diff):
		if diff[i] > 0 and diff[i] > maxi:
			sec.append([diff[i], i + 1])
			maxi = diff[i]
		i += 1
	sum1 = len(n)
	for i in range(len(sec)):
		sum1 += sec[i][1]
	print(sum1)
	t -= 1


for test_i in range(int(input())):
	s = input()
	l = len(s)
	i = 0
	cur_sum = 0
	init = 0
	res = 0
	while i < l:
		while i < l:
			cur_sum += 1 if s[i] == '+' else -1
			i += 1
			if cur_sum < -init:
				break
		init += 1
		res += i
	if cur_sum == -init:
		res += l
	print(res)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
t = 1
t = int(input())
for _ in range(t):
	s = input()
	ans = 0
	curr = 0
	x = 0
	for i in range(len(s)):
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < x:
			ans += i + 1
			x = curr
	ans += len(s)
	print(ans)


for i in range(int(input())):
	s = list(input())
	res = 0
	counter = 0
	for i in range(len(s)):
		if s[i] == '+':
			res = res + 1
			counter = counter + 1
		elif counter > 0:
			res = res + 1
			counter = counter - 1
		else:
			res = res + i + 2
	print(res)


T = input()
for j in range(0, int(T)):
	s = input()
	array = []
	array.append(len(s))
	health = 0
	min = 0
	for i in range(0, len(s)):
		if s[i] == '-':
			health = health - 1
		else:
			health = health + 1
		if health < min:
			array.append(i + 1)
			min = health
	print(sum(array))


t = int(input())
for _ in range(t):
	s = input()
	a = b = res = curr = temp = 0
	for i in s:
		res += 1
		if i == '+':
			a += 1
		else:
			b += 1
		if b > a + curr:
			temp += res
			curr += 1
	print(temp + res)


from sys import stdin, stdout
from sys import maxsize
input = stdin.readline

def solve():
	pass
test = 1
test = int(input().strip())
for t in range(0, test):
	s = list(input().strip())
	n = len(s)
	for i in range(n):
		if s[i] == '+':
			s[i] = 1
		else:
			s[i] = -1
	for i in range(1, n):
		s[i] += s[i - 1]
	res = 0
	j = 0
	if min(s) < 0:
		for i in range(-min(s) + 1):
			while j < n and i + s[j] >= 0:
				j += 1
			if j < n:
				res += j + 1
			else:
				res += j
		print(res)
	else:
		print(len(s))
	ans = solve()


import math
t = int(input())
for _ in range(t):
	s = input()
	a = 0
	b = 0
	dp = [0 for x in range(len(s))]
	res = 0
	boo = 0
	curr = 0
	temp = 0
	arr = []
	for i in s:
		res += 1
		if i == '+':
			a += 1
		else:
			b += 1
		if b > a:
			boo = 1
			if b > a + curr:
				temp += res
				curr += 1
	print(temp + res)


for i in range(int(input())):
	string = list(input())
	cnt = 0
	arr = []
	index = 0
	flag = False
	for i in range(len(string)):
		if string[i] == '+':
			cnt += 1
			arr.append(cnt)
		else:
			cnt -= 1
			arr.append(cnt)
	temp = -1
	ans = 0
	for i in range(len(arr)):
		if arr[i] == temp:
			ans += i + 1
			temp -= 1
			index = i
			if i == len(arr) - 1:
				if arr[i] == temp + 1:
					ans += len(arr)
				flag = True
	if not flag:
		ans += len(arr)
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	res = len(s)
	(m, p) = (0, 0)
	cur = 0
	for i in range(0, len(s)):
		if s[i] == '+':
			p += 1
		else:
			m += 1
		if cur + p - m < 0:
			cur += 1
			res += i + 1
	print(res)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scan_int = lambda : int(input())
scan_string = lambda : input().rstrip()
read_list = lambda : list(read())
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	s = scan_string()
	ps = [0]
	for x in s:
		if x == '+':
			ps.append(ps[-1] + 1)
		else:
			ps.append(ps[-1] - 1)
	summ = 0
	last = 0
	for i in range(len(ps)):
		if ps[i] < last:
			summ += i
			last = ps[i]
	print(summ + len(s))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(scan_int()):
	solve()


from sys import stdin

def help():
	stri = stdin.readline().strip()
	sumi = 0
	posi = []
	n = len(stri)
	sum_yet = 0
	po = 0
	for i in range(n):
		sumi += -1 if stri[i] == '-' else 1
		po += 1 if stri[i] == '+' else -1
		if sumi < 0 and stri[i] == '-' and (po < 0):
			posi.append(i)
			po = 0
	ans = 0
	for i in posi:
		ans += i + 1
	ans += n
	print(ans)
for _ in range(int(input())):
	help()


n = int(input())
for i in range(n):
	s = input()
	c = 0
	ans = 0
	for k in range(len(s)):
		if s[k] == '+':
			c += 1
		else:
			c -= 1
		if c < 0:
			c = 0
			ans += k + 1
	print(ans + len(s))


import math
from collections import deque
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < abs(max_ending_here):
			max_so_far = max_ending_here
	return max_so_far

def longestsubarray(arr, n, k):
	current_count = 0
	max_count = 0
	for i in range(0, n, 1):
		if arr[i] % k != 0:
			current_count += 1
		else:
			current_count = 0
		max_count = max(current_count, max_count)
	return max_count

def main():
	s = input()
	res = 0
	init = 0
	f = 0
	n = len(s)
	p = 0
	m = 0
	s1 = 0
	j = 0
	f = 0
	l = []
	while j < n:
		if s[j] == '+':
			p += 1
		elif p > 0:
			p -= 1
		else:
			l.append(j + 1)
		j += 1
	for j in range(0, len(l)):
		s1 += l[j]
	print(s1 + n)
t = int(input())
for i in range(0, t):
	main()


T = int(input())
for _ in range(T):
	a = input()
	s = 0
	init = 0
	ans = 0
	for (i, c) in enumerate(a, start=1):
		x = 1 if c == '+' else -1
		s += x
		if init + s < 0:
			ans += i
			init += 1
	ans += len(a)
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	li = []
	x = 0
	for j in range(len(s)):
		if s[j] == '-':
			x -= 1
		else:
			x += 1
		li.append(x)
	init = -1
	res = 0
	for i in range(len(s)):
		if li[i] == init:
			res += i + 1
			init -= 1
	res += len(s)
	print(res)


for i in range(int(input())):
	s = input()
	l = res = len(s)
	t = 0
	for j in range(l):
		if s[j] == '-':
			if t > 0:
				t -= 1
			else:
				res += j + 1
		else:
			t += 1
	print(res)


t = int(input())
while t > 0:
	t = t - 1
	s = input()
	cf = []
	sums = 0
	for ele in s:
		if ele == '+':
			sums += 1
		else:
			sums -= 1
		cf.append(sums)
	res = len(s)
	curr = 0
	for i in range(len(cf)):
		if s[i] == '+':
			curr += 1
		elif curr == 0:
			res += i + 1
		else:
			curr -= 1
	print(res)


for I in range(int(input())):
	s = input()
	tot = 0
	dic = {}
	for (i, char) in enumerate(s):
		if char == '+':
			tot += 1
		else:
			tot -= 1
		if tot < 0:
			if tot not in dic:
				dic[tot] = [i + 1]
			else:
				dic[tot].append(i + 1)
	res = 0
	for i in range(len(s) + 1):
		check = (i + 1) * -1
		if check not in dic:
			res += len(s)
			break
		else:
			for j in range(len(dic[check])):
				if dic[check][j] >= abs(check):
					res += dic[check][j]
					break
	print(res)


n = int(input())
for x in range(n):
	s = input()
	ans = len(s)
	t = 0
	for i in range(len(s)):
		if s[i] == '-':
			if t > 0:
				t -= 1
			else:
				ans += i + 1
		else:
			t += 1
	print(ans)


import sys
from collections import defaultdict, deque, Counter
import math
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
getS = lambda : input().strip()
getN = lambda : int(input())
getList = lambda : list(map(int, input().split()))
getZList = lambda : [int(x) - 1 for x in input().split()]
INF = 10 ** 20
MOD = 10 ** 9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)

def solve():
	s = getS()
	tmp = 0
	rui = []
	for c in s:
		if c == '+':
			tmp += 1
		else:
			tmp -= 1
		rui.append(tmp)
	tgt = -1
	ans = len(s)
	for (i, ru) in enumerate(rui):
		if ru == tgt:
			ans += i + 1
			tgt -= 1
	print(ans)

def main():
	n = getN()
	for _ in range(n):
		solve()
main()


import math
t = int(input())
for hello in range(t):
	s = list(input())
	res = 0
	cur = 0
	mic = [0]
	for i in range(len(s)):
		res = res + 1
		if s[i] == '+':
			cur = cur + 1
		else:
			cur = cur - 1
		if cur < 0:
			cur += 1
			mic.append(i + 1)
	print(sum(mic) + len(s))


t = int(input())
while t:
	t -= 1
	s = input()
	n = len(s)
	(c, r) = (0, 0)
	for i in range(n):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
		if c < 0:
			r += i + 1
			c = 0
	print(r + n)


for _ in range(int(input())):
	s = input()
	l = len(s)
	a = []
	p = 0
	for i in range(l):
		if s[i] == '+':
			p += 1
		else:
			p -= 1
		if p < 0:
			a.append([p, i + 1])
	a.sort()
	if len(a) == 0:
		print(l)
		continue
	m = a[0][1]
	a.sort(key=lambda x: x[1])
	res = 0
	n = 0
	for i in range(len(a)):
		if abs(a[i][0]) > n:
			res += (abs(a[i][0]) - n) * a[i][1]
			n = abs(a[i][0])
	res += l
	print(res)


for _ in range(int(input())):
	s = input()
	k = len(s)
	n = p = 0
	res = 0
	for i in range(k):
		if s[i] == '+':
			p += 1
		else:
			n += 1
		if n > p:
			res += i + 1
			p += 1
	print(res + k)


for _ in range(int(input())):
	st = list(input())
	ar = [0 for i in range(len(st))]
	if st[0] == '+':
		ar[0] = 1
	else:
		ar[0] = -1
	for i in range(1, len(st)):
		if st[i] == '+':
			ar[i] = ar[i - 1] + 1
		else:
			ar[i] = ar[i - 1] - 1
	ans = 0
	if min(ar) < 0:
		c = abs(min(ar))
		k = -1
		for i in range(len(ar)):
			if abs(k) > c:
				break
			elif ar[i] == k:
				ans += i + 1
				k -= 1
	ans += len(st)
	print(ans)


for u in range(int(input())):
	s = input()
	t = 0
	l = []
	for i in range(len(s)):
		if s[i] == '+':
			t += 1
		else:
			t -= 1
		if t < 0:
			l.append([t, i + 1])
	l = sorted(l)
	if len(l) == 0:
		print(len(s))
	else:
		a = l[0][1]
		l = sorted(l, key=lambda x: x[1])
		ans = 0
		temp = 0
		for i in range(len(l)):
			if abs(l[i][0]) > temp:
				ans += (abs(l[i][0]) - temp) * l[i][1]
				temp = abs(l[i][0])
		ans += len(s)
		print(ans)


import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
for i in range(r()):
	a = list(input())
	n = len(a) - 1
	cnt = 0
	res = 0
	for i in range(n):
		if a[i] == '-':
			cnt -= 1
		else:
			cnt += 1
		if cnt < 0:
			cnt += 1
			res += i + 1
	if res == 0:
		print(n)
	elif cnt != -1:
		print(res + n)
	else:
		print(res)


t = int(input())
for i in range(t):
	s = input().strip()
	dp = [0]
	c = 0
	j = 0
	while j < len(s):
		if s[j] == '+':
			c = c + 1
		else:
			c = c - 1
		if c >= 0:
			dp.append(dp[-1] + 1)
		else:
			dp.append(dp[-1] + j + 2)
			c = 0
		j = j + 1
	print(dp[-1])


for u in range(int(input())):
	s = input()
	(c, r) = (0, 0)
	for i in range(len(s)):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
		if c < 0:
			r += i + 1
			c = 0
	r += len(s)
	print(r)


for _ in range(int(input())):
	s = input()
	n = len(s)
	cur = 0
	ans = n
	for (i, v) in enumerate(s):
		if v == '-':
			if cur > 0:
				cur -= 1
			else:
				ans += i + 1
		else:
			cur += 1
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for test in range(t):
	s = input()
	s = s[0:-1]
	counter = 0
	check = 1
	ans = 0
	for i in range(len(s)):
		if s[i] == '+':
			counter -= 1
		else:
			counter += 1
		if counter == check:
			ans += i + 1
			check += 1
	print(ans + len(s))


t = int(input())
for _ in range(t):
	s = [i for i in input()]
	score = [0] * len(s)
	ct = 0
	for i in range(len(s)):
		if s[i] == '+':
			ct += 1
		else:
			ct -= 1
		score[i] = ct
	last_seen = 0
	tct = 0
	for i in range(len(score)):
		if score[i] < last_seen:
			tct += (i + 1) * abs(score[i] - last_seen)
			last_seen = score[i]
	tct += len(score)
	print(tct)


for _ in range(int(input())):
	s = list(input())
	l = len(s)
	curr = 0
	ans = 0
	for i in range(l):
		if s[i] == '-':
			if curr == 0:
				ans += i + 1
			else:
				curr -= 1
		else:
			curr += 1
	ans += l
	print(ans)


import os
import operator
from collections import defaultdict
import sys
from io import BytesIO, IOBase
import bisect

def main():
	for _ in range(int(input())):
		s = input()
		ct = 0
		ans = len(s)
		arr = []
		for i in s:
			if i == '-':
				ct -= 1
			else:
				ct += 1
			arr.append(ct)
		pos = 0
		for i in range(len(s)):
			ok = False
			for j in range(pos, len(s)):
				if arr[j] == -1 * (i + 1):
					ans += j + 1
					ok = True
					pos = j + 1
					break
			if not ok:
				break
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	mydict = {'+': 1, '-': -1}
	s = [mydict[x] for x in list(stdin.readline().strip())]
	n = len(s)
	prefix = [0] * n
	count = 0
	for x in range(n):
		count += s[x]
		prefix[x] = count
	count = -1
	mylist = [0] * n
	total = 0
	for x in range(n):
		if prefix[x] == count:
			total += x + 1
			count -= 1
	stdout.write(str(total + n) + '\n')


for lo in range(int(input())):
	st = input()
	c1 = 0
	c2 = 0
	n = len(st)
	res = 0
	for i in range(n):
		if st[i] == '+':
			c1 += 1
			res += 1
		elif c1 == 0:
			res += i + 2
		else:
			res += 1
			c1 -= 1
	print(res)


for _ in range(int(input())):
	s = list(input())
	n = len(s)
	narr = list(map(lambda o: -1 if o == '-' else 1, s))
	sm = 0
	lt = 0
	for i in range(n):
		tmp = 0
		for j in range(lt, n):
			tmp += narr[j]
			if tmp < 0:
				sm += j + 1
				lt = j + 1
				break
		if tmp > -1:
			break
	print(sm + n)


import collections
import os
import sys
from io import BytesIO, IOBase
import math
ins = lambda : [int(x) for x in input()]
inp = lambda : int(input())
inps = lambda : [int(x) for x in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		s = input()
		mx = 0
		cnt = 0
		s = list(s)
		dc = collections.defaultdict(int)
		for (pos, ch) in enumerate(s):
			if ch == '+':
				cnt += 1
			else:
				cnt -= 1
			if cnt < 0 and abs(cnt) not in dc:
				dc[abs(cnt)] = pos + 1
			mx = min(mx, cnt)
		if abs(mx) == 0:
			print(len(s))
		else:
			neg = abs(mx)
			ans = 0
			for (k, v) in dc.items():
				ans += v
			print(ans + len(s))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	s = inputstring()
	a = []
	if s[0] == '+':
		a.append(1)
	else:
		a.append(-1)
	for i in range(1, len(s)):
		if s[i] == '+':
			a.append(a[i - 1] + 1)
		else:
			a.append(a[i - 1] - 1)
	ans = 0
	cur = -1
	for i in range(len(a)):
		if a[i] == cur:
			ans += i + 1
			cur -= 1
	print(ans + len(s))


import random

def naive(ss):
	res = 0
	init = 0
	s = ' ' + ss
	for init in range(100000):
		cur = init
		ok = True
		for i in range(1, len(s)):
			res += 1
			if s[i] == '+':
				cur += 1
			else:
				cur -= 1
			if cur < 0:
				ok = False
				break
		if ok:
			break
	return res

def optimal(s):
	n = len(s)
	ans = 0
	curr = 0
	m = 0
	for i in range(n):
		if s[i] == '+':
			m += 1
			curr += 1
		elif m > 0:
			m -= 1
			curr += 1
		else:
			curr += 1
			ans += curr
	ans += curr
	return ans
t = int(input())
for i in range(t):
	s = input()
	print(optimal(s))


t = int(input())
for _ in range(t):
	s = input()
	size = len(s)
	d = [-1] * (size + 1)
	cur = 0
	x = 1
	for char in s:
		if char == '-':
			cur += 1
		else:
			cur -= 1
		if cur >= 0:
			if d[cur] == -1:
				d[cur] = x
		x += 1
	res = 0
	i = 1
	while i < size + 1:
		if d[i] != -1:
			res += d[i]
		else:
			break
		i += 1
	res += size
	print(res)


import sys
import math
from collections import defaultdict as dd
mod = 1000000007
T = 1
T = int(sys.stdin.readline())
for _ in range(T):
	s = input()
	x = 0
	m = len(s)
	n = m
	d = {}
	for i in range(n):
		if s[i] == '-':
			x -= 1
		else:
			x += 1
		m = min(x, m)
		if x < 0:
			if x not in d:
				d[x] = i + 1
	if m >= 0:
		print(n)
	else:
		k = 0
		for i in d:
			k += d[i]
		print(n + k)


for ii in range(int(input())):
	s = input()
	i = 0
	curr = 0
	sav = 0
	dic = {}
	while i < len(s):
		if s[i] == '+':
			sav += 1
			i += 1
			pass
		elif s[i] == '-':
			sav -= 1
			i += 1
		if sav < 0:
			dic[curr] = i
			curr += 1
			sav += 1
	dic[curr] = len(s)
	print(sum(list(dic.values())))


for _ in range(int(input())):
	s = [x for x in input()]
	ans = res = curr = 0
	for i in range(len(s)):
		res += 1
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < 0:
			curr = 0
			ans += res
	ans += res
	print(ans)


import sys
input = sys.stdin.readline

def testcase():
	ans = 0
	p = 0
	c = 0
	S = input().strip()
	for s in S:
		if c < 0:
			c += 1
		p += 1
		if s == '+':
			c += 1
		else:
			c -= 1
		if c >= 0:
			continue
		ans += p
	else:
		if c >= 0:
			ans += p
		elif c < 0:
			ans += len(S) * abs(c)
	print(ans)

def main():
	t = int(input())
	for _ in range(t):
		testcase()
main()


for _ in range(int(input())):
	s = input()
	ans = 0
	bal = 0
	now = 0
	am = 0
	for i in s:
		if i == '+':
			bal += 1
		elif i == '-':
			bal -= 1
		ch = -bal
		if ch > now:
			ans += (am + 1) * (ch - now) + 1
			now = ch
		else:
			ans += 1
		am += 1
	print(ans)


def pluses_minuses(s):
	l = len(s)
	p = 0
	res = 0
	for i in range(l):
		if s[i] == '+':
			p += 1
			if i == l - 1:
				return res + l
			continue
		elif s[i] == '-':
			if p > 0:
				p -= 1
				if i == l - 1:
					return res + l
				continue
			else:
				res += i + 1
				if i == l - 1:
					return res + l
t = int(input())
a = []
for i in range(t):
	a.append(input())
for x in a:
	print(pluses_minuses(x))


t = int(input())
for tt in range(t):
	s = input()
	sa = []
	for x in s:
		if x == '-':
			sa.append(-1)
		else:
			sa.append(1)
	ints = [0]
	for i in range(len(sa)):
		ints.append(ints[-1] + sa[i])
	gph = [0]
	for i in range(1, len(ints)):
		gph.append(min(gph[-1], ints[i]))
	for i in range(len(gph)):
		gph[i] *= -1
	lvls = sorted(list(set(gph)))
	p2 = 0
	final = []
	for p1 in range(len(lvls)):
		cnt = 0
		while gph[p2] == lvls[p1]:
			cnt += 1
			p2 += 1
			if p2 == len(gph):
				break
		final.append(cnt)
	sums = [0]
	for i in range(len(final)):
		sums.append(sums[-1] + final[i])
	print(sum(sums) - 1)


from __future__ import division, print_function
import os
import sys, math
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	Test = int(input())
	while Test:
		Test -= 1
		s = input()
		n = len(s)
		v = []
		for i in range(n):
			v.append(1 if s[i] == '+' else -1)
			if i == 0:
				continue
			v[i] += v[i - 1]
		ma = dict()
		for i in range(n):
			if ma.get(v[i]) is None:
				ma[v[i]] = i + 1
		ma = dict(sorted(ma.items()))
		ans = n
		for (key, value) in ma.items():
			if key >= 0:
				break
			ans += value
		print(ans)
	return None
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for s in range(t):
	pm = input()
	cur = 0
	res = 0
	for i in range(len(pm)):
		if pm[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			res += i + 1
			cur = 0
	else:
		print(res + len(pm))


t = int(input())
while t:
	s = input()
	n = len(s)
	res = 0
	i = 0
	prev = 0
	while i < n:
		while i < n and s[i] == '-':
			if prev == 0:
				res += i + 1
			else:
				prev -= 1
			i += 1
		while i < n and s[i] == '+':
			prev += 1
			i += 1
	print(res + n)
	t -= 1


t = int(input())
for i in range(t):
	res = 0
	a = input()
	l = len(a)
	cnt = 0
	add = 0
	num = 0
	for i in range(l):
		if a[i] == '-':
			cnt -= 1
			if cnt + num < 0:
				res += i + 1
				num += 1
		elif a[i] == '+':
			cnt += 1
			if cnt + num < 0:
				res += i + 1
				num += 1
	if cnt + num >= 0:
		res += l
	print(res)


for _ in range(int(input())):
	s = list(input())
	d = {}
	c = 0
	mx = 0
	for i in range(len(s)):
		if s[i] == '-':
			c = c - 1
		else:
			c = c + 1
		if c < 0:
			if c not in d.keys():
				d[c] = i
		mx = min(c, mx)
	mx = mx * -1
	res = 0
	for i in range(1, mx + 1):
		i = i * -1
		res = res + (d[i] + 1)
	res = res + len(s)
	print(res)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
t = int(input())
for _ in range(t):
	s = input()
	val_list = []
	init = 0
	ans = 0
	now = 0
	for j in range(len(s)):
		i = s[j]
		if i == '+':
			init += 1
			val_list.append(init)
		else:
			init -= 1
			val_list.append(init)
		if now + init < 0:
			ans += j + 1
			now += 1
	ans += len(s)
	print(ans)


t = int(input())
mov = []
for k in range(t):
	tira = input()
	n = len(tira)
	nm = 0
	np = 0
	compt = n
	aturades = 0
	for i in range(n):
		if tira[i] == '+':
			np += 1
		else:
			nm += 1
		if nm - np > aturades:
			compt += i + 1
			aturades += 1
	mov.append(compt)
for i in range(t):
	print(mov[i])


def solve():
	s = input()
	mn = 0
	ans = 0
	curr = 0
	for i in range(len(s)):
		if s[i] == '-':
			curr -= 1
		else:
			curr += 1
		if curr < mn:
			ans += i + 1
			mn = curr
	ans += len(s)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	s = str(input())
	minm = 0
	arr = []
	total = 0
	for i in range(len(s)):
		if s[i] == '-':
			total -= 1
		else:
			total += 1
		if minm > total:
			arr.append((total, i))
			minm = total
	if minm >= 0:
		print(len(s))
		continue
	total = 0
	for j in arr:
		total += j[1] + 1
	print(total + len(s))


for i in range(int(input())):
	a = input()
	b = 0
	c = 0
	d = 0
	for j in range(len(a)):
		c += (b - c) * int(b < c)
		if a[j] == '+':
			b += 1
		else:
			b -= 1
		d += (j + 1) * int(b < c)
	d += len(a)
	print(d)


def pandm(string):
	res = len(string)
	curr = 0
	m = 0
	for i in range(0, len(string)):
		if string[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < m:
			m = curr
			res += i + 1
	return res
t = int(input())
for i in range(t):
	print(pandm(input()))


import sys
import math
from math import factorial, inf, gcd
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
from bisect import *
import random
sys.setrecursionlimit(10 ** 5)

def rarray():
	return [int(i) for i in input().split()]
t = 1
t = int(input())
for ii in range(t):
	s = input()
	n = len(s)
	ans = [0] * n
	h = {}
	for (i, j) in enumerate(s):
		if i == 0:
			ans[i] = -1 if j == '-' else 1
		else:
			ans[i] = ans[i - 1]
			if j == '-':
				ans[i] -= 1
			else:
				ans[i] += 1
		if ans[i] < 0 and ans[i] not in h:
			h[ans[i]] = i
	a = sorted(h.keys(), reverse=True)
	last = 0
	res = 0
	for i in a:
		res += (last - i) * (h[i] + 1)
		last = i
	res += n
	print(res)


t = int(input())
for _ in range(t):
	S = input()
	p = 0
	res = len(S)
	for (i, s) in enumerate(S, 1):
		if s == '+':
			p += 1
		else:
			p -= 1
		if p < 0:
			res += i
			p += 1
	print(res)


import math
for _ in range(int(input())):
	s = input()
	a = [s[0]]
	ans = 0
	sum = 0
	for i in range(len(s)):
		a.append(s[i])
		if a[-1] == '+':
			sum += 1
		if a[-1] == '-':
			sum -= 1
		if sum < 0:
			ans += i + 2
			sum = 0
		else:
			ans += 1
	print(ans)


for _ in range(int(input())):
	s = input()
	ss = []
	for i in range(len(s)):
		if s[i] == '-':
			ss.append(-1)
		else:
			ss.append(1)
		if i > 0:
			ss[i] += ss[i - 1]
	tmp = 0
	ans = len(ss)
	ok = True
	for x in ss:
		if x < 0:
			ok = False
			break
	if ok:
		print(ans)
		continue
	for i in range(len(ss)):
		if tmp > ss[i]:
			ans += i + 1
			tmp = ss[i]
	print(ans)


for _ in range(int(input())):
	s = ' ' + input()
	c = 0
	res = 0
	l = -1
	for i in range(1, len(s)):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
		if c == l:
			res += i
			l -= 1
	print(res + len(s) - 1)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')

def cal(s):
	res = 0
	for init in range(1000):
		cur = init
		ok = True
		for i in range(len(s)):
			res = res + 1
			if s[i] == '+':
				cur = cur + 1
			else:
				cur = cur - 1
			if cur < 0:
				ok = False
				break
		if ok:
			break
	print(res)
t = fi()
while t > 0:
	t -= 1
	s = si()
	n = len(s)
	pre = [0]
	d = {}
	for i in range(len(s)):
		if s[i] == '+':
			pre.append(pre[-1] + 1)
		else:
			pre.append(pre[-1] - 1)
		if pre[-1] not in d:
			d[pre[-1]] = i + 1
	mini = 10 ** 18
	p = -min(pre)
	c = 0
	for i in range(p):
		c += d[-i - 1]
	print(c + n)


for i in range(int(input())):
	s = input()
	c = 0
	res = 0
	f = 1
	if s.count('+') == 0:
		res = len(s) * (len(s) + 1) // 2
		res += len(s)
	else:
		for i in range(len(s)):
			res += 1
			if s[i] == '+':
				c += 1
			else:
				c -= 1
			if c < 0:
				res = res + i + 1
				c = 0
	print(res)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	ans = 0
	grid = [0] * (n + 1)
	score = 0
	maxmin = 0
	for i in range(n):
		if s[i] == '-':
			score -= 1
		else:
			score += 1
		maxmin = min(maxmin, score)
	score = 0
	for i in range(n):
		if s[i] == '-':
			score -= 1
		else:
			score += 1
		if -1 * score - 1 >= 0:
			if grid[-1 * score - 1] == 0:
				grid[-1 * score - 1] = i + 1
	for i in range(-1 * maxmin, n):
		grid[i] = 0
	grid[n] = n
	print(sum(grid))


t = int(input())
while t > 0:
	s = input()
	(cp, ans) = (0, 0)
	for i in range(len(s)):
		if s[i] == '+':
			cp += 1
		elif cp > 0:
			cp -= 1
		else:
			ans += i + 1
	ans += len(s)
	print(ans)
	t -= 1


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for i in range(INT()):
	s = input()
	a = [0 for i in range(len(s))]
	if s[0] == '-':
		a[0] = -1
	else:
		a[0] = 1
	for i in range(1, len(s)):
		a[i] = a[i - 1]
		if s[i] == '-':
			a[i] -= 1
		else:
			a[i] += 1
	cur = 0
	su = 0
	for i in range(len(s)):
		if cur + a[i] < 0:
			su += i + 1
			cur += 1
	su += len(s)
	print(su)


for _ in range(int(input())):
	s = input()
	n = len(s)
	d = {}
	cur = 0
	ma = 0
	for i in range(n):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0 and cur not in d:
			d[cur] = i + 1
		ma = min(ma, cur)
	ma = -ma
	ans = 0
	for i in range(ma):
		ans += d[-(i + 1)]
	print(ans + n)


t = int(input())
for k in range(t):
	s = input()
	(c, prev, ans) = (0, 0, len(s))
	for i in range(len(s)):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
		if c < prev:
			prev = c
			ans = ans + i + 1
	print(ans)


t = int(input())
for _ in range(t):
	s = list(input())
	n = len(s)
	r = 0
	m = 0
	for i in range(n):
		r = r + 1
		if s[i] == '+':
			m = m + 1
		else:
			m = m - 1
		if m < 0:
			m = 0
			k = i + 1
			r = r + k
	print(r)


for _ in range(int(input())):
	s = input()
	res = 0
	(plus, minus) = (0, 0)
	(j, le) = (0, len(s))
	for i in range(le):
		if s[i] == '+':
			plus = plus + 1
		else:
			minus = minus + 1
		if minus - plus > j:
			res += i + 1
			j += 1
	res += le
	print(res)


n = int(input())
for q in range(n):
	ent = input()
	t = len(ent)
	soma = [0] * t
	s = 0
	menor = 0
	menores = set()
	cont = t
	for k in range(t):
		if ent[k] == '+':
			c = 1
		else:
			c = -1
		soma[k] = c + s
		s += c
		if soma[k] < menor:
			menor = soma[k]
			menores.add(soma[k])
	for i in range(t):
		if soma[i] in menores:
			menores.remove(soma[i])
			cont += i + 1
	print(cont)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input().rstrip()
	minima = 0
	accum = 0
	ans = 0
	for (i, ch) in enumerate(s):
		if ch == '-':
			accum -= 1
			if accum < minima:
				minima = accum
				ans += i + 1
		else:
			accum += 1
	print(ans + len(s))


t = int(input())
ans = []
for k in range(t):
	s = input()
	n = len(s)
	res = 0
	cur = 0
	for i in range(n):
		res += 1
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			cur = 0
			res += i + 1
	ans.append(res)
for i in range(t):
	print(ans[i])


for _ in range(int(input())):
	s = input()
	l = len(s)
	pre = [0] * (l + 1)
	for i in range(l):
		if s[i] == '+':
			pre[i] = pre[i - 1] + 1
		else:
			pre[i] = pre[i - 1] - 1
	ans = 0
	c = 0
	for i in range(l):
		if pre[i] < c:
			ans += i + 1
			c -= 1
	ans += l
	print(ans)


import os
is_dev = 'vscode' in os.environ
if is_dev:
	inF = open('cfEdu90/in.txt', 'r')
	outF = open('cfEdu90/out.txt', 'w')

def ins(r):
	return list(map(int, r.split(' ')))

def inputT():
	if is_dev:
		return inF.readline()
	else:
		return input()

def printT(data):
	if is_dev:
		return outF.write(data + '\n')
	else:
		return print(data)
for _ in range(int(inputT())):
	s = inputT()
	res = 0
	cur = 0
	for (i, x) in enumerate(s):
		res += 1
		if cur == 0 and x == '-':
			res += i + 1
		elif x == '+':
			cur += 1
		else:
			cur -= 1
	printT(f'{res}')
if is_dev:
	print(open('cfEdu90/out.txt', 'r').read() == open('cfEdu90/outactual.txt', 'r').read())


def solution():
	for _ in range(int(input())):
		s = input()
		res = len(s)
		cur = 0
		for i in range(len(s)):
			if s[i] == '-':
				cur -= 1
			else:
				cur += 1
			if cur < 0:
				res += i + 1
				cur = 0
		print(res)
solution()


n = int(input())
answer_arr = []
for i in range(n):
	s = input()
	steps = 0
	health = 0
	for k in range(len(s)):
		if s[k] == '+':
			health += 1
		else:
			health -= 1
		if health < 0:
			steps += k + 1
			health = 0
		steps += 1
	answer_arr.append(steps)
for elem in answer_arr:
	print(elem)


import sys, math
for _ in range(int(input())):
	s = input()
	ans = len(s)
	mas = [0]
	for i in s:
		if i == '-':
			mas.append(mas[-1] - 1)
		else:
			mas.append(max(mas[-1], 0) + 1)
	for i in range(len(mas)):
		if mas[i] < 0:
			ans += i
	print(ans)


a = int(input())
for i in range(0, a):
	s = input()
	res = 0
	num = float('inf')
	count = 0
	index = 0
	brr = []
	for i in range(0, len(s)):
		if s[i] == '+':
			count = count + 1
		else:
			count = count - 1
		if count < num:
			num = count
			if num < 0:
				brr.append(i + 1)
	print(sum(brr) + len(s))


t = int(input())
for i in range(t):
	s = input()
	if s.count('+') == len(s):
		print(len(s))
	else:
		cur = 0
		init = 0
		res = len(s)
		for i in range(len(s)):
			if s[i] == '+':
				cur += 1
			else:
				cur -= 1
			if cur < init:
				init += 1
				cur = init
				res += i + 1
		print(res)


t = int(input())
for _ in range(t):
	s = str(input())
	h = len(s)
	l = []
	ctr = 0
	for i in range(h):
		if s[i] == '+':
			ctr += 1
			l.append(ctr)
		else:
			ctr -= 1
			l.append(ctr)
	val = 0
	k = -1
	m = -1 * min(l)
	for i in range(h):
		if l[i] == k:
			val += i + 1
			k -= 1
		if k == m:
			break
	val += h
	print(val)


def g(al):
	ll = []
	ct = 0
	for i in al:
		if i == '+':
			ct = ct + 1
			ll.append(ct)
		else:
			ct = ct - 1
			ll.append(ct)
	minn = min(ll)
	if minn >= 0:
		return len(ll)
	j = 0
	ct = -1
	summ = 0
	while ll[j] != minn:
		if ll[j] == ct:
			summ = summ + j + 1
			ct = ct - 1
		j = j + 1
	summ = summ + j + 1
	summ = summ + len(al)
	return summ
for tc in range(int(input())):
	s = input()
	print(g(s))


t = int(input())
for _ in range(t):
	s = input()
	res = 0
	d = {}
	num = 0
	for i in range(len(s)):
		if s[i] == '-':
			num -= 1
		elif s[i] == '+':
			num += 1
		if num in d:
			d[num].append(i)
		else:
			d[num] = [i]
	for i in range(len(s) + 1):
		if -(i + 1) not in d:
			res += len(s)
			break
		if d[-(i + 1)] != []:
			res += d[-(i + 1)][0] + 1
			d[-(i + 1)].pop(0)
		else:
			res += len(s)
			break
	print(res)


for _ in range(int(input())):
	s = input()
	min_balance = 0
	min_balance_idx = 0
	balance = 0
	first_failure = [-1] * (len(s) + 1)
	for (i, ch) in enumerate(s):
		if ch == '+':
			balance += 1
		else:
			balance -= 1
		if balance < min_balance:
			min_balance = balance
			first_failure[-balance - 1] = i
	cnt = len(s)
	for i in range(-min_balance):
		cnt += first_failure[i] + 1
	print(cnt)


for _ in range(0, int(input())):
	s = input()
	ans = 0
	max = 0
	sum = 0
	for i in range(len(s)):
		if s[i] == '-':
			sum += 1
		else:
			sum -= 1
		if sum > max:
			ans += i + 1
			max = sum
	ans += len(s)
	print(ans)


from collections import deque
import sys

def inp():
	return sys.stdin.readline().strip()
for _ in range(int(inp())):
	ans = 0
	s = inp()
	prefix = [0] * len(s)
	for i in range(len(s)):
		if s[i] == '+':
			prefix[i] += 1
		else:
			prefix[i] -= 1
		if i - 1 >= 0:
			prefix[i] += prefix[i - 1]
	imp = []
	used = set()
	for i in range(len(prefix)):
		if prefix[i] < 0 and prefix[i] not in used:
			imp.append((prefix[i], i))
			used.add(prefix[i])
	mn = 0
	for i in range(len(imp)):
		if mn + imp[i][0] >= 0:
			continue
		else:
			diff = abs(mn - imp[i][0])
			mn = imp[i][0]
			ans += diff * (imp[i][1] + 1)
	print(ans + len(s))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import bisect
testcases = int(input())
for j in range(testcases):
	parity = input()
	res = 0
	prefsum = []
	maxneg = 0
	store = 0
	used = set([])
	sorts = []
	for s in range(len(parity)):
		if parity[s] == '+':
			store += 1
		else:
			store -= 1
		if store < maxneg:
			maxneg = store
		if not store in used:
			sorts.append((store, s))
		used.add(store)
		prefsum.append(store)
	if maxneg > 0:
		print(len(prefsum))
	else:
		sorts.sort(key=lambda x: x[0])
		newy = [k[0] for k in sorts]
		for s in range(abs(maxneg)):
			ind = bisect.bisect_left(newy, -(s + 1))
			res += sorts[ind][1] + 1
		res += len(prefsum)
		print(res)


for _ in range(int(input())):
	s = str(input())
	c = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
			if c < 0:
				ans += i + 1
				c = 0
	if c >= 0:
		ans += len(s)
	print(ans)


import sys
import math as mt
t = int(input())
for _ in range(t):
	s = input()
	ans = 0
	cnt = 0
	res = 0
	for i in range(len(s)):
		if s[i] == '+':
			cnt += 1
		else:
			cnt -= 1
		if cnt < 0:
			ans += i + 1
			cnt += 1
	print(ans + len(s))


for _ in range(int(input())):
	x = 0
	s = input()
	p = 0
	n = len(s)
	for i in range(n):
		if s[i] == '+':
			p += 1
		elif p > 0:
			p -= 1
		elif p == 0:
			x += i + 1
	print(x + n)


def solve():
	s = input()
	min_val = 0
	res = 0
	cur = 0
	for i in range(len(s)):
		if s[i] == '-':
			cur -= 1
		else:
			cur += 1
		if min_val > cur:
			res += i + 1
			min_val = cur
	print(res + len(s))
for i in range(int(input())):
	solve()


for _ in range(int(input())):
	c = 0
	d = 0
	s = list(str(input()))
	i = 0
	r = 0
	for i in range(len(s)):
		if s[i] == '+':
			c += 1
			d += 1
		else:
			t1 = c - 1
			if t1 < 0:
				c = 0
				d += i + 2
			else:
				c = t1
				d += 1
	print(d)


for test in range(int(input())):
	s = input()
	neg = 0
	res = 0
	cur = 0
	for i in range(len(s)):
		res += 1
		if s[i] == '-':
			neg += 1
			if neg > cur:
				cur += 1
				res += i + 1
		else:
			cur += 1
	print(res)


from math import *
tests = int(input())
for t in range(tests):
	s = input()
	cur = 0
	init = 0
	res = 0
	for i in range(len(s)):
		delta = 1 if s[i] == '+' else -1
		cur += delta
		if init + cur < 0:
			res += i + 1
			init += 1
	res += len(s)
	print(res)


def main():
	t = int(input())
	for _ in range(t):
		s = input()
		prev = 0
		prefix = [0] * len(s)
		for (i, c) in enumerate(s):
			if c == '+':
				prefix[i] = max(prev + 1, 1)
			else:
				prefix[i] = prev - 1
			prev = prefix[i]
		result = 0
		for (i, p) in enumerate(prefix):
			if p < 0:
				result += i + 1
		result += len(s)
		print(result)
main()


t = int(input())
while t:
	s = input()
	pref = []
	for i in range(len(s) + 1):
		pref.append(i)
	if s[0] == '+':
		pref[0] = 1
	else:
		pref[0] = -1
	for i in range(1, len(s)):
		if s[i] == '+':
			pref[i] = pref[i - 1] + 1
		else:
			pref[i] = pref[i - 1] - 1
	res = 1
	ans = 0
	for i in range(len(s) + 1):
		if pref[i] == -1 * res and i != len(s):
			ans += i + 1
			res += 1
		elif i == len(s):
			ans += len(s)
	print(ans)
	t = t - 1


for t in range(int(input())):
	s = input().strip()
	a = [[0, 0]]
	c = 0
	for i in range(len(s)):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
			if -c > a[-1][0]:
				a.append([-c, i])
	n = len(a)
	res = 0
	for i in range(n + 1):
		cur = i + 1
		if cur >= n:
			res += len(s)
			break
		(c, j) = a[cur]
		res += j + 1
	print(res)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def func(x):
	t = 0
	for i in arr:
		if i <= x:
			t += i
	return t

def solve():
	for _ in range(int(input())):
		s = input()
		arr = [[-1, 1][i == '+'] for i in s]
		for i in range(1, len(s)):
			arr[i] += arr[i - 1]
		ans = 0
		sett = set()
		for i in range(len(s)):
			if arr[i] < 0 and arr[i] not in sett:
				ans += i + 1
				sett.add(arr[i])
		print(ans + len(s))
solve()


from sys import stdin, stdout
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()
import math

def p(a):
	print(' '.join(list(map(str, a))))
from collections import Counter

def solve():
	s = S()
	l = len(s)
	res = 0
	cur = 0
	for x in range(l):
		if s[x] == '+':
			cur += 1
		else:
			cur -= 1
			if cur < 0:
				res += x + 1
				cur += 1
	print(l + res)
for i in range(IN()):
	solve()


for _ in range(int(input())):
	x = input()
	(cnt, cnt1, ans) = (0, 0, 0)
	for i in x:
		cnt += 1
		if i == '+':
			cnt1 += 1
		if i == '-':
			cnt1 -= 1
		if cnt1 < 0:
			ans += cnt
			cnt1 = 0
	ans += cnt
	print(ans)


import math

def solve(s):
	n = len(s)
	r = n
	L = [0] * n
	if s[0] == '+':
		L[0] = 1
	else:
		L[0] = -1
	for i in range(1, n):
		if s[i] == '+':
			L[i] = L[i - 1] + 1
		else:
			L[i] = L[i - 1] - 1
	f = [True] * n
	N = [-math.inf] * n
	i = 0
	while i < n:
		t = L[i]
		if t < 0 and f[-1 - t]:
			N[-1 - t] = i
			f[-1 - t] = False
		i += 1
	for i in range(0, n):
		if N[i] != -math.inf:
			r += N[i] + 1
		else:
			return r
	return r
t = int(input())
for i in range(0, t):
	s = str(input())
	print(solve(s))


from sys import stdin, stdout

def II():
	return int(stdin.readline())

def SI():
	return stdin.readline()[:-1]
t = II()
for _ in range(t):
	s = SI()
	(curr, res) = (0, 0)
	for (i, c) in enumerate(s):
		if c == '+':
			curr += 1
		else:
			curr -= 1
		if curr < 0:
			res += i + 1
			curr = 0
	res += len(s)
	stdout.write(str(res) + '\n')


def my_code(s):
	res = 0
	temp = 0
	for i in range(len(s)):
		if s[i] == '+':
			res += 1
			temp += 1
		elif temp > 0:
			res += 1
			temp -= 1
		else:
			res += 2
			res += i
	return res
for i in range(int(input())):
	print(my_code(input()))


for _ in range(int(input())):
	s = input()
	x = len(s)
	res = 0
	(k, j) = (0, 0)
	for i in range(x):
		if s[i] == '-':
			k += 1
		else:
			j += 1
		if k > j:
			res += i + 1
			(k, j) = (0, 0)
	print(res + x)


t = int(input())
while t > 0:
	t -= 1
	x = input()
	a = 0
	n = 0
	for i in range(len(x)):
		if x[i] == '-':
			n -= 1
		else:
			n += 1
		if n < 0:
			a += i + 1 + 1
			n = 0
		else:
			a += 1
	print(a)


def read_int():
	n = int(input())
	return n

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints

def solve(s):
	l = len(s)
	cur = 0
	res = 0
	dp = [0 for _ in range(l + 1)]
	for i in range(l):
		if s[i] == '+':
			dp[i + 1] = dp[i] + 1
			cur += 1
		elif cur > 0:
			dp[i + 1] = dp[i] + 1
			cur -= 1
		else:
			dp[i + 1] = dp[i] + (i + 2)
	return dp[-1]
t = read_int()
for case in range(t):
	s = input()
	sol = solve(s)
	print(sol)


for _ in range(int(input())):
	s = input()
	(r, v) = (0, 0)
	for i in range(len(s)):
		if s[i] == '+':
			v += 1
			r += 1
			continue
		if v != 0:
			v -= 1
			r += 1
		else:
			r += i + 2
	print(r)


def countFreq(arr, n, mp, s):
	for i in range(n):
		if arr[i] not in mp.keys():
			mp[arr[i]] = i + 1
	for x in mp:
		if x < 0:
			s += mp[x]
	return s
for _ in range(int(input())):
	a = list(str(input()))
	(br, cur) = ([0] * len(a), 0)
	for i in range(len(a)):
		cur = cur + 1 if a[i] == '+' else cur - 1
		br[i] = cur
	print(countFreq(br, len(br), dict(), 0) + len(a))


t = int(input())
for _ in range(t):
	s = input()
	leading = 0
	minuses = 0
	plusses = 0
	for x in s:
		if x == '+':
			plusses += 1
		elif plusses > 0:
			plusses -= 1
		else:
			minuses += 1
	lst = [0] * (minuses + 1)
	ans = len(s)
	for i in range(minuses + 1):
		num = i
		if num == 0:
			index = 0
			tmp = 0
			while index < len(s) and num > 0:
				tmp += 1
				if s[index] == '+':
					num += 1
				else:
					num -= 1
				index += 1
			ans += tmp
			lst[num] = tmp
		else:
			ans += lst[num - 1]
			index = lst[num - 1]
			temp = num
			num = 1
			tmp = 0
			while index < len(s) and num > 0:
				tmp += 1
				if s[index] == '+':
					num += 1
				else:
					num -= 1
				index += 1
			ans += tmp
			lst[temp] = tmp + lst[temp - 1]
	print(ans)


for _ in range(int(input())):
	s = input()
	count = 0
	(m, p) = (0, 0)
	ans = 0
	for i in range(len(s)):
		if s[i] == '-':
			m += 1
		else:
			p += 1
		if m - p > count:
			count += 1
			ans += i + 1
	ans += len(s)
	print(ans)


import sys
import random
from math import *

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

def rlinput():
	return list(map(int, input().split()))

def trinput():
	return tuple(rinput())

def srlinput():
	return sorted(list(map(int, input().split())))

def NOYES(fl):
	if fl:
		print('NO')
	else:
		print('YES')

def YESNO(fl):
	if fl:
		print('YES')
	else:
		print('NO')

def main():
	q = list(map(lambda x: {'+': 1, '-': -1}[x], input())) + [-10000000000.0]
	(n, k, s, res) = (len(q), 0, 0, 0)
	for i in range(n):
		s += q[i]
		if s < 0:
			res += i + 1
			s += 1
	print(res - 1)
for inytd in range(iinput()):
	main()


n = int(input())
lst = []
for _ in range(n):
	SIGNS = input()
	l = len(SIGNS)
	res = 0
	plus = 0
	for idx in range(l):
		if SIGNS[idx] == '+':
			if idx == l - 1:
				res += l
			plus += 1
		elif plus != 0:
			if idx == l - 1:
				res += l
			plus -= 1
		elif idx == l - 1:
			res += l + l
		else:
			res += idx + 1
	lst.append(str(res))
print('\n'.join(lst))


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	res = [0 for _ in range(n)]
	for i in range(n):
		if s[i] == '-':
			res[i] = -1
		else:
			res[i] = 1
	for i in range(n - 1):
		res[i + 1] += res[i]
	if min(res) >= 0:
		print(n)
	else:
		memo = -min(res)
		m = 0
		ans = 0
		for i in range(n):
			ans += max(memo - m, 0) + 1
			m = max(m, -res[i])
		print(ans)


for nt in range(int(input())):
	s = input()
	n = len(s)
	cur = 0
	loop = 0
	ans = 0
	for i in range(n):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur + loop < 0:
			ans += i + 1
			loop += 1
	print(ans + n)


for _ in range(int(input())):
	s = input()
	cur = 0
	res = len(s)
	for (index, c) in enumerate(s, start=1):
		if c == '-':
			cur -= 1
		else:
			cur += 1
		if cur == -1:
			cur = 0
			res += index
	print(res)


def res(strOfPlusesAndMinuses):
	total = nPluses = nMinuses = 0
	for i in range(len(strOfPlusesAndMinuses)):
		if strOfPlusesAndMinuses[i] == '+':
			nPluses += 1
			total += 1
		elif nPluses == nMinuses:
			total += i + 2
		else:
			nMinuses += 1
			total += 1
	return total
nTestCases = int(input())
testCases = tuple((input() for x in range(nTestCases)))
tuple((print(res(testCase)) for testCase in testCases))


t = int(input())
for _ in range(t):
	s = input()
	val = [-1] * (len(s) + 2)
	p = 0
	m = 0
	for x in range(len(s)):
		if s[x] == '-':
			m += 1
		else:
			p += 1
		if m - p > 0 and val[m - p] == -1:
			val[m - p] = x + 1
	ans = 0
	for x in range(1, len(val)):
		if val[x] != -1:
			ans += val[x]
		else:
			ans += len(s)
			break
	print(ans)


z = int(input())
for h in range(z):
	s = input()
	m = 0
	ans = 0
	for i in range(len(s)):
		ans += 1
		if s[i] == '-':
			m -= 1
		else:
			m += 1
		if m < 0:
			m = 0
			ans += i + 1
	print(ans)


for i in range(int(input())):
	s = input()
	tmp = 0
	ans = 0
	for i in range(len(s)):
		ans += 1
		if s[i] == '-':
			tmp -= 1
		else:
			tmp += 1
		if tmp < 0:
			ans += i + 1
			tmp = 0
	print(ans)


for _ in range(int(input())):
	s = list(input())
	res = 0
	cur = 0
	n = len(s)
	for i in range(n):
		res = res + 1
		if s[i] == '+':
			cur = cur + 1
		else:
			cur = cur - 1
		if cur < 0:
			cur = 0
			res += i + 1
	print(res)


def solution(s):
	sign = [0, 0]
	val = len(s)
	for i in range(len(s)):
		j = i + 1
		if s[i] == '+':
			sign[0] = sign[0] + 1
		else:
			sign[1] = sign[1] + 1
			val1 = sign[0]
			val2 = sign[1]
			if val1 < val2:
				val = val + j
				sign[1] = sign[1] - 1
	return val
for _ in range(int(input())):
	s = input()
	print(solution(s))


for j in range(int(input())):
	s = input()
	(x, y) = (0, 0)
	l = len(s)
	for i in range(l):
		if s[i] == '-':
			x += 1
		else:
			y += 1
		if x > y:
			l += i + 1
			x -= 1
	print(l)


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	s = input().strip()
	n = len(s)
	(plus, minus) = (0, 0)
	ans = 0
	for i in range(n):
		if s[i] == '-':
			minus += 1
		else:
			plus += 1
		if minus > plus:
			ans += i + 1
			(minus, plus) = (0, 0)
	print(ans + n)


nb_cases = int(input())
for case in range(nb_cases):
	s = input()
	res = 0
	somme_pm = 0
	for x in range(len(s)):
		if s[x] == '+':
			somme_pm += 1
		else:
			somme_pm -= 1
		if somme_pm < 0:
			res += x + 1
			somme_pm += 1
	res += len(s)
	print(res)


t = int(input())
for _ in range(t):
	s = input()
	dic = {}
	n = len(s)
	ans = 0
	arr = []
	curr = 0
	for i in range(n):
		if s[i] == '-':
			curr -= 1
		else:
			curr += 1
		arr.append(curr)
	for i in range(n):
		if arr[i] < 0 and arr[i] not in dic:
			ans += 1 + i + 1
			dic[arr[i]] = 1
		else:
			ans += 1
	print(ans)


def f(s):
	total = 0
	current = 0
	smallestsofar = 0
	for char in s:
		total += smallestsofar
		if char == '+':
			current += 1
		else:
			current -= 1
		smallestsofar = min(smallestsofar, current)
	total += (1 - smallestsofar) * len(s)
	return total
numberoftests = int(input())
for _ in range(numberoftests):
	print(f(input()))


for _ in range(int(input())):
	s = input()
	n = len(s)
	plus = 0
	ans = 0
	for i in range(n):
		if s[i] == '-':
			plus = max(plus, 0)
			if plus == 0:
				ans += i + 2
			else:
				ans += 1
				plus -= 1
		else:
			ans += 1
			plus += 1
	print(ans)


for t in range(int(input())):
	a = input()
	n = len(a)
	s = n
	c = 0
	m = 0
	for i in range(n):
		if a[i] == '+':
			c += 1
		else:
			c -= 1
			if c < m:
				m = c
				s += i + 1
	print(s)


for _ in range(int(input())):
	s = input()
	ans = len(s)
	cur = 0
	for i in range(len(s)):
		if s[i] == '-':
			cur -= 1
		else:
			cur += 1
		if cur < 0:
			ans += i + 1
			cur = 0
	print(ans)


import sys
t = int(sys.stdin.readline())
ans_arr = []
for i in range(t):
	s = sys.stdin.readline().strip()
	n = len(s)
	w = 0
	x = 0
	count = 0
	res = 0
	while x < n:
		if s[x] == '+':
			count += 1
		else:
			count -= 1
		if w + count < 0:
			res += x + 1
			w += 1
		x += 1
	res += n
	ans_arr.append(str(res))
print('\n'.join(ans_arr))


for t in range(int(input())):
	s = list(input())
	n = len(s)
	prev_offset = 0
	res = n
	cur = 0
	for k in range(n):
		if s[k] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < prev_offset:
			prev_offset = cur
			res += k + 1
	print(res)


t = int(input())
ans = []
for i in range(t):
	s = input()
	res = 0
	curr = 0
	ti = 0
	te = 0
	ll = []
	minn = 0
	se = {}
	for j in range(len(s)):
		if s[j] == '+':
			ll.append(te + 1)
			te += 1
			if te not in se.keys():
				se[te] = [j]
			else:
				se[te].append(j)
			if te < minn:
				minn = te
		else:
			ll.append(te - 1)
			te -= 1
			if te not in se.keys():
				se[te] = [j]
			else:
				se[te].append(j)
			if te < minn:
				minn = te
	res += len(s)
	if te == len(s):
		ans.append(res)
		continue
	for k in range(abs(minn)):
		res += min(se[-1 * (k + 1)]) + 1
	ans.append(res)
for an in ans:
	print(an)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
from collections import defaultdict as dd
from bisect import bisect
for i in range(t):
	s = input()
	c = 0
	d = dd(int)
	l = []
	for j in s:
		if j == '-':
			c -= 1
		else:
			c += 1
		l.append(c)
	res = 0
	x = True
	y = min(l)
	for j in range(len(l)):
		if d[l[j]] == 0 and l[j] < 0:
			res += j + 1
			d[l[j]] = 1
		if l[j] == y:
			res += len(s)
			x = False
			break
	print(res)


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
(t,) = mp()
for _ in range(t):
	s = cin()[:-1]
	res = cur = 0
	n = len(s)
	for i in range(n):
		if s[i] == '+':
			cur += 1
		elif not cur:
			res += i + 1
		else:
			cur -= 1
	res += n
	cout(str(res) + '\n')


t = int(input())
for _ in range(0, t):
	st = str(input())
	d = {}
	var = 0
	for i in range(0, len(st)):
		if st[i] == '+':
			var += 1
		else:
			var -= 1
		if var < 0 and var not in d:
			d[var] = i + 1
	ans = sum(d.values())
	print(ans + len(st))


t = int(input())
for u in range(t):
	s = input()
	cp = 0
	hak = 0
	out = 0
	p = 1
	i = 0
	n = len(s)
	while i < n:
		if s[i] == '+':
			cp += 1
			if cp > hak - 1:
				p = 1
		else:
			cp -= 1
			if hak + cp < 0:
				out += i + 1
				hak += 1
				p = 0
		i += 1
	print(out + n)


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		s = SI()
		cur = 0
		fir = [0] * len(s)
		for (i, c) in enumerate(s):
			if c == '+':
				cur += 1
			else:
				cur -= 1
			if cur < 0 and fir[cur] == 0:
				fir[cur] = i + 1
		print(sum(fir) + len(s))
main()


t = int(input())
for i in range(t):
	s = input()
	m = 0
	res = 0
	bal = 0
	kolm = 0
	last = False
	for l in range(len(s)):
		if s[l] == '-':
			bal -= 1
			kolm += 1
		else:
			bal += 1
		if bal < 0:
			res += l + 1
			bal += 1
	if bal >= 0:
		res += len(s)
	elif bal == len(s) * -1:
		res += len(s)
	print(res)


from sys import stdin, stdout

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(input())):
			s = R()
			prefix_sum = {}
			for j in range(len(s) - 1):
				if j == 0:
					prefix_sum[j] = 1 if s[j] == '+' else -1
				else:
					prefix_sum[j] = (1 if s[j] == '+' else -1) + prefix_sum[j - 1]
			cur = res = 0
			for j in range(len(s) - 1):
				if cur + prefix_sum[j] < 0:
					cur += 1
					res += j + 1
				if j == len(s) - 2:
					res += j + 1
			ans.append(str(res))
		W('\n'.join(ans))

def main():
	s = SOLVE()
	s.solve()
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2
from math import *
for _ in range(int(input())):
	st = input()
	n = len(st)
	pref = [0]
	for i in range(n):
		if st[i] == '-':
			pref.append(pref[-1] - 1)
		else:
			pref.append(pref[-1] + 1)
	pref = pref[1:]
	ans = 0
	mini = 0
	for i in range(n):
		if pref[i] < mini:
			ans += i + 1
			mini = min(mini, pref[i])
	print(n + ans)


def solve(p, n):
	ind = []
	c = 0
	for i in range(n):
		if p[i] == '+':
			c += 1
		else:
			c -= 1
		if c < 0:
			ind.append(i)
			c = 0
	if not ind:
		return n
	arr = [ind[0], -1]
	for j in range(1, len(ind)):
		if ind[j] - ind[j - 1] > 1:
			arr.append(ind[j] - ind[j - 1] - 1)
		arr.append(-1)
	arr.append(n - (ind[-1] + 1))
	ans = 0
	x = 0
	for i in range(len(arr)):
		x += abs(arr[i])
		if arr[i] == -1:
			ans += x
	return ans + x
for _ in range(int(input())):
	p = list(input())
	n = len(p)
	print(solve(p, n))


import sys
import math
from collections import defaultdict
for _ in range(int(input())):
	s1 = list(input())
	x = len(s1)
	p = [0] * x
	a = 0
	b = 0
	for i in range(len(s1)):
		if s1[i] == '+':
			a += 1
		else:
			a -= 1
		p[i] = a
	ans = 0
	tt = 0
	for i in range(len(s1)):
		if p[i] + tt >= 0:
			ans += 1
		else:
			ans += i + 2
			tt += 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	s = input()
	res = 0
	init = 0
	l = []
	d = []
	ctr = 0
	for (p, i) in enumerate(s):
		if i == '+':
			ctr += 1
		l.append(ctr)
		d.append(p + 1 - 2 * ctr)
	offset = 0
	tot = 0
	for (p, i) in enumerate(d):
		if i > offset:
			tot += (i - offset) * (p + 1)
			offset = i
	print(tot + len(s))


import sys

def fi():
	return sys.stdin.readline()
for _ in range(int(fi())):
	s = fi().strip('\n')
	counter = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '-':
			counter -= 1
		else:
			counter += 1
		if counter < 0:
			ans += i + 1
			counter = 0
	ans += len(s)
	print(ans)


try:
	k = int(input())
	for i in range(k):
		s = input()
		res = 0
		brkpt = -1
		res = 0
		while True:
			temp = 0
			flg = 1
			for z in range(brkpt + 1, len(s)):
				if s[z] == '+':
					temp += 1
				else:
					temp -= 1
				if temp < 0:
					flg = 0
					brkpt = z
					res = res + brkpt + 1
					break
			if flg == 1:
				res += len(s)
				break
		print(res)
except Exception:
	pass


t = int(input())
for _ in range(t):
	s = input()
	if s[0] == '+':
		l = [1]
	else:
		l = [-1]
	mi = l[0]
	r = 0
	if l[0] == -1:
		r = 1
		l[0] = 0
		f = 0
	f = 1
	for i in range(1, len(s)):
		if s[i] == '+':
			x = 1
		else:
			x = -1
		w = l[i - 1] + x
		if w < 0:
			w = w + 1
			r = r + i + 1
		l.append(w)
		if w < mi:
			mi = w
	print(r + len(s))


t = int(input())
for _ in range(t):
	s = input()
	l = []
	n = 0
	for i in s:
		if i == '-':
			n -= 1
		else:
			n += 1
		l.append(n)
	r = 0
	n = max(0, -min(l))
	j = 0
	for i in range(n):
		j = l.index(-i - 1, j)
		r += j + 1
	r += len(l)
	print(r)


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		ans = 0
		s = input()
		s = s[:len(s) - 1]
		ls = len(s)
		if True:
			p = []
			(x, lp) = (0, 0)
			for i in range(ls):
				if s[i] == '+':
					x += 1
				else:
					x -= 1
				if x < 0:
					if lp < abs(x):
						p.append(i + 1)
						lp += 1
			for i in range(ls + abs(x)):
				if i >= lp:
					ans += ls
					break
				else:
					ans += p[i]
			print(ans)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	s = input()
	lens = len(s)
	p = []
	t = 0
	for i in range(lens):
		if s[i] == '+':
			t += 1
		else:
			t -= 1
		p.append(t)
	mn = 1
	f = []
	for i in range(lens):
		if p[i] == -mn:
			f.append(i + 1)
			mn += 1
	print(sum(f) + lens)


for _ in range(int(input())):
	str = input()
	qi = out = 0
	for i in range(len(str)):
		if str[i] == '+':
			qi += 1
		else:
			qi -= 1
		if qi < 0:
			out += i + 1
			qi = 0
	print(out + len(str))


for _ in range(int(input())):
	a = input()
	x = 0
	ss = len(a)
	min = 0
	for i in range(len(a)):
		if a[i] == '+':
			x += 1
		else:
			x -= 1
		if x < min:
			min = x
			ss += i + 1
	print(ss)


def main():
	t = int(input())
	for _ in range(t):
		needed_cur = 0
		res = 0
		index = 1
		string = input()
		for x in string:
			res += 1
			if x == '+':
				needed_cur += 1
			else:
				needed_cur -= 1
				if needed_cur < 0:
					needed_cur += 1
					res += index
			index += 1
		print(res)
main()


numTest = int(input())
for count in range(numTest):
	listCarac = input()
	result = 0
	aux = 0
	for count in range(len(listCarac)):
		if listCarac[count] == '-':
			aux = aux - 1
		else:
			aux = aux + 1
		if aux < 0:
			result = result + count + 1
			aux = 0
	print(result + len(listCarac))


for q in range(int(input())):
	s = input()
	balance = []
	if s[0] == '-':
		balance = [-1]
	else:
		balance = [1]
	for i in range(1, len(s)):
		if s[i] == '-':
			balance.append(balance[-1] - 1)
		else:
			balance.append(balance[-1] + 1)
	ans = len(s)
	now = 0
	n = len(s)
	for i in range(n):
		if balance[i] < now:
			ans += i + 1
			now = balance[i]
	print(ans)


for case in range(int(input())):
	signs = input()
	res = 0
	sum = 0
	for (i, sign) in enumerate(signs):
		if sign == '+':
			sum += 1
		else:
			sum -= 1
		if sum < 0:
			res += i + 1
			sum = 0
	print(res + len(signs))


t = int(input())
for _ in range(t):
	s = input()
	res = 0
	val = 0
	for i in range(len(s)):
		if s[i] == '+':
			res += 1
		else:
			res -= 1
		if res < 0:
			val += i + 1
			res = 0
	print(val + len(s))


for i in range(int(input())):
	s = input()
	answer = 0
	nums = []
	for i in range(len(s)):
		if i == 0:
			if s[i] == '-':
				nums.append(-1)
			else:
				nums.append(1)
		elif s[i] == '-':
			nums.append(nums[i - 1] - 1)
		else:
			nums.append(nums[i - 1] + 1)
	added = 0
	for (i, val) in enumerate(nums):
		while val + added < 0:
			added += 1
			answer += i + 1
	answer += len(s)
	print(answer)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
N = 10 ** 9 + 7
for _ in range(I()):
	s = S()
	cnt = 0
	cur = 0
	for i in range(len(s)):
		if s[i] == '-':
			cur += 1
		elif cur < 0:
			cur -= 1
		else:
			cur = -1
		if cur > 0:
			cnt += i + 1
	print(cnt + len(s))


def find_numb(s, a):
	nu = 0
	for i in range(0, len(s)):
		if s[i] == '+':
			nu += 1
		else:
			nu -= 1
		if nu < 0:
			if -1 * nu not in a:
				a[-1 * nu] = i
	return a
t = int(input())
while t:
	t = t - 1
	s = input()
	res = 0
	init = 0
	a = find_numb(s, {})
	while True:
		cur = init
		ok = True
		if cur + 1 in a:
			res += a[cur + 1] + 1
			ok = False
		else:
			res += len(s)
		if ok:
			break
		init += 1
	print(res)


import os
import sys
from io import BytesIO, IOBase
import threading
from math import floor, ceil
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7

def main():
	for _ in range(int(input())):
		s = input()
		gain = [0] * len(s)
		d = dict()
		d[0] = 0
		for i in range(len(s)):
			if s[i] == '-':
				gain[i] = gain[i - 1] - 1
				d[gain[i]] = i
			else:
				gain[i] = gain[i - 1] + 1
				d[gain[i]] = i
		t_it = max(0, -min(gain))
		ad = [len(s) - 1] * (len(s) + 1)
		for (ind, i) in enumerate(gain):
			if i < 0 and ad[-(i + 1)] == len(s) - 1:
				ad[-(i + 1)] = ind
		res = 0
		for i in range(t_it + 1):
			res += ad[i] + 1
		print(res)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from itertools import accumulate
for _ in range(int(input())):
	s = input()
	l = len(s)
	t = [1 if s[i] == '+' else -1 for i in range(l)]
	t = list(accumulate(t))
	now = 0
	ans = 0
	for i in range(l):
		if t[i] < now:
			ans += i + 1
			now = t[i]
		if i == l - 1:
			ans += i + 1
	print(ans)


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil, pi
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919]

def primef(n, plst=[]):
	if n == 1:
		return plst
	else:
		for m in primes:
			if n % m == 0:
				return primef(n // m, plst + [m])
		return primef(1, plst + [n])

def scoreBad(s):
	res = 0
	counter = 0
	while True:
		cur = int(counter)
		ok = True
		for i in range(len(s)):
			res += 1
			if s[i] == '+':
				cur += 1
			else:
				cur -= 1
			if cur < 0:
				ok = False
				break
		counter += 1
		if ok:
			break
	return res
t = int(input())
for i in range(t):
	s = list(input())
	prefix = [0 for _ in range(len(s))]
	if s[0] == '+':
		prefix[0] += 1
	else:
		prefix[0] -= 1
	for i in range(1, len(s)):
		prefix[i] = prefix[i - 1]
		if s[i] == '+':
			prefix[i] += 1
		else:
			prefix[i] -= 1
	tot = 0
	count = 0
	for j in range(len(prefix)):
		if prefix[j] + count < 0:
			tot += j + 1
			count += 1
	tot += len(s)
	print(tot)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		s = rs()
		curr = 0
		z = []
		k = 0
		ans = len(s)
		for i in range(len(s)):
			if s[i] == '+':
				curr += 1
			else:
				curr -= 1
			if curr + k < 0:
				k += 1
				ans += i + 1
		wi(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import math
tt = int(input())
for i in range(0, tt):
	s = input()
	(cur, mn, res) = (0, 0, len(s))
	for i in range(len(s)):
		cur += 1 if s[i] == '+' else -1
		if cur < mn:
			mn = cur
			res += i + 1
	print(res)


import os
import sys
from io import BytesIO, IOBase

def solution(s):
	(res, init) = (0, 0)
	n = len(s)
	s = 'x' + s
	pl = s.count('+')
	pref = [0]
	for i in range(1, n + 1):
		if s[i] == '+':
			pref.append(pref[-1] + 1)
		else:
			pref.append(pref[-1] - 1)
	res = [n]
	mn = float('inf')
	for i in range(1, n + 1):
		if pref[i] < 0 and pref[i] < mn:
			res.append(i)
			mn = pref[i]
	write(sum(res))

def main():
	for _ in range(r_int()):
		s = input()
		solution(s)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
	s = input()
	res = cur = mn = 0
	n = len(s)
	for i in range(n):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < mn:
			res += i + 1
			mn = cur
	print(res + n)


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	s = input()
	prfx = [0] * len(s)
	prfx[0] = 1 if s[0] == '+' else -1
	last = 0
	for i in s[1:]:
		if i == '+':
			prfx[last + 1] = prfx[last] + 1
		else:
			prfx[last + 1] = prfx[last] - 1
		last += 1
	last = 0
	res = 0
	for i in range(len(s)):
		if last + prfx[i] < 0:
			res += i + 1
			last += 1
	res += len(s)
	print(res)


import sys
input = sys.stdin.readline
for f in range(int(input())):
	s1 = input()
	tot = 0
	sol = 0
	mn = 0
	for i in range(len(s1) - 1):
		if s1[i] == '+':
			tot += 1
		else:
			tot -= 1
		if tot < mn:
			foo = mn - tot
			mn = tot
			sol += foo * (i + 1)
	sol += len(s1) - 1
	print(sol)


t = int(input())
for cas in range(t):
	s = input()
	mi = 0
	cur = 0
	for c in s:
		if c == '+':
			cur += 1
		else:
			cur -= 1
			mi = min(mi, cur)
	init = -mi
	if init == 0:
		print(len(s))
	else:
		l = [100000000 for i in range(init)]
		cur = 0
		for i in range(len(s)):
			if s[i] == '+':
				cur += 1
			else:
				cur -= 1
				if cur < 0:
					l[-cur - 1] = min(l[-cur - 1], i + 1)
		print(sum(l) + len(s))


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	s = input()
	n = len(s)
	sumTill = []
	cur = 0
	for i in s:
		if i == '+':
			cur += 1
		else:
			cur -= 1
		sumTill.append(cur)
	need = sumTill[-1] * -1
	notSurvive = []
	for i in sumTill:
		if i < 0:
			notSurvive.append(-1 * i - 1)
		else:
			notSurvive.append(-1)
	ans = n
	ma = -1
	for i in range(n):
		if notSurvive[i] > ma:
			ans += i + 1
			ma = notSurvive[i]
	print(ans)


from bisect import *
a = int(input())
for i in range(a):
	s = input()
	ans = []
	mini = []
	if s[0] == '+':
		mini = [-1]
	else:
		mini = [1]
	for i in range(1, len(s)):
		if s[i] == '+':
			mini.append(mini[-1] - 1)
		else:
			mini.append(mini[-1] + 1)
	maxa = [max(mini[0], 0)]
	for i in range(1, len(mini)):
		maxa.append(max(mini[i], maxa[-1], 0))
	t = max(maxa)
	total = 0
	for i in range(t + 1):
		r = bisect_right(maxa, i)
		total += min(len(maxa), r + 1)
	print(total)


t = int(input())
for _ in range(t):
	s = str(input())
	count = 0
	curr = 0
	arr = []
	ese = 0
	for i in range(len(s)):
		if s[i] == '+':
			curr = curr + 1
		else:
			curr = curr - 1
		arr.append(curr)
	for i in range(len(arr)):
		if arr[i] >= ese:
			pass
		else:
			count = count + i + 1
			ese = arr[i]
	print(count + len(s))


import sys
from math import sqrt
input = sys.stdin.readline

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	t = inp()
	for l in range(t):
		s = instr()
		ans = len(s)
		cur = 0
		for i in range(len(s)):
			if s[i] == '+':
				cur += 1
			else:
				cur -= 1
			if cur < 0:
				ans += i + 1
				cur = 0
		print(ans)
main()


import math
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	dp = []
	ct = 0
	mp = math.inf
	for i in range(n):
		if s[i] == '-':
			ct -= 1
		else:
			ct += 1
		dp.append(ct)
		mp = min(mp, ct)
	if mp < 0:
		lim = abs(mp)
	else:
		lim = 0
	rev = 0
	x = 0
	for i in range(n):
		while dp[i] < -x and x <= lim:
			x += 1
			rev += i + 1
	rev += n
	print(rev)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
from math import log, log2, sqrt, factorial, cos, tan, sin, radians, ceil, floor
import bisect
from decimal import *
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		s = si()
		c = 0
		l = []
		for i in range(len(s)):
			if s[i] == '+':
				c += 1
				if c < 1:
					c = 1
			else:
				c -= 1
			l.append(c)
		ans = 0
		for i in range(len(s)):
			if l[i] < 0:
				ans += i + 1
		ans += len(s)
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	s = SI()
	count = 0
	d = [-1] * len(s)
	for i in range(len(s)):
		if s[i] == '+':
			count += 1
		else:
			count -= 1
		if count < 0:
			temp = abs(count) - 1
			if d[temp] == -1:
				d[temp] = i
	ans = 0
	for i in range(len(d)):
		if d[i] != -1:
			ans += d[i] + 1
		else:
			break
	print(ans + len(s))


for _ in range(int(input())):
	s = str(input())
	n = len(s)
	curr = 0
	res = 0
	for i in range(n):
		res += 1
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < 0:
			res += i + 1
			curr = 0
	print(res)


t = int(input())
for _ in range(t):
	s = input()
	arr = [int(0) for _ in range(len(s))]
	mini = [int(0) for _ in range(len(s))]
	ptr = 0
	for i in range(len(s)):
		if s[i] == '+':
			arr[i] = arr[i - 1] + 1
		else:
			arr[i] = arr[i - 1] - 1
		if arr[i] < ptr:
			for j in range(i, i + ptr - arr[i]):
				mini[j] = i + 1
			ptr = arr[i]
	print(sum(mini) + len(s))


from math import ceil

def solve():
	S = input()
	res = 0
	s = 0
	for i in range(len(S)):
		if S[i] == '-':
			s -= 1
			if s < 0:
				res += i + 1
				s += 1
		else:
			s += 1
	res += len(S)
	print(res)
for cnt in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	s = input()
	arr = [0 for _ in range(len(s))]
	arr[0] = 1 if s[0] == '+' else -1
	for i in range(1, len(s)):
		arr[i] = arr[i - 1] + (1 if s[i] == '+' else -1)
	minima = min(arr)
	if minima >= 0:
		print(len(s))
	else:
		negatives = [0 for _ in range(-minima)]
		for i in reversed(range(len(s))):
			if arr[i] < 0:
				negatives[arr[i]] = i
		print(-minima + sum(negatives) + len(s))


from bisect import bisect_left
T = int(input())
for t in range(T):
	s = input()
	cum = [0]
	cur = 0
	for i in s:
		if i == '+':
			cur += 1
		else:
			cur -= 1
		cum.append(min(cur, cum[-1]))
	cum = [-i for i in cum]
	ans = 0
	for i in range(cum[-1] + 1):
		cur = bisect_left(cum, i + 0.5)
		ans += cur
	ans -= 1
	print(ans)


for _ in range(int(input())):
	s = input()
	c = 0
	d = {}
	ans = 0
	for i in range(len(s)):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
		if c < 0 and c not in d:
			d[c] = True
			ans += i + 1
	ans += len(s)
	print(ans)


import sys
import math
from decimal import *

def I():
	return int(sys.stdin.readline())

def IL():
	return list(map(int, sys.stdin.readline().strip().split()))

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))

def solve():
	tt = I()
	for ii in range(tt):
		s = input()
		l = [-1 if x == '-' else 1 for x in s]
		cum = []
		res = 0
		for ll in l:
			res += ll
			cum.append(res)
		tot = min(cum)
		if tot < 0:
			tot *= -1
		else:
			tot = 0
		ans = 0
		x = tot + 1
		for cc in cum:
			ans += x
			if cc < 0:
				xx = tot + cc + 1
				if xx < x:
					x = xx
		print(ans)
solve()


for __ in range(int(input())):
	S = input()
	(cur, lim, res) = (0, 0, len(S))
	for i in range(len(S)):
		cur += 1 if S[i] == '+' else -1
		if cur < lim:
			res += i + 1
			lim = cur
	print(res)


for _ in range(int(input())):
	s = list(input())
	n = len(s)
	v = [0] * (n + 1)
	curr = 0
	for i in range(0, n):
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < 0:
			if v[abs(curr)] == 0:
				v[abs(curr)] = i + 1
	val = n
	for i in range(1, n + 1):
		if v[i] != 0:
			val += v[i]
		else:
			break
	print(val)


for _ in range(int(input())):
	s = input()
	l = []
	x = 0
	for i in s:
		if i == '-':
			x -= 1
		else:
			x += 1
		l.append(x)
	x = 0
	if min(l) >= 0:
		print(len(s))
		continue
	else:
		x = abs(min(l))
		y = 0
		z = x + 1
		s = 0
		for i in l:
			s += z
			if i < y:
				z += i - y
				y = i
		print(s)


T = int(input())
while T > 0:
	s = input()
	mi = float('inf')
	cur = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
			mi = min(mi, cur)
	al = max(1, 1 - mi)
	res = 0
	cand = al
	least = 0
	for i in range(len(s)):
		if s[i] == '+':
			res += cand
			least += 1
		else:
			res += cand
			least -= 1
			if least < 0:
				cand -= 1
				least = 0
	print(res)
	T -= 1


for _ in range(int(input())):
	s = input()
	c = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '-' and c == 0:
			ans += i + 1
		elif s[i] == '-' and c > 0:
			c -= 1
		elif s[i] == '+':
			c += 1
	print(ans + len(s))


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
from bisect import bisect, bisect_right, bisect_left

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	st = input()
	c = 0
	ans = 0
	for (ind, val) in enumerate(st, 1):
		if val == '-':
			c -= 1
		else:
			c += 1
		if c < 0:
			ans += ind
			c += 1
	return ans + len(st)

def main():
	print(solve())
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
import math
from math import sqrt, log, log2
from fractions import Fraction
import random

def simulation(s):
	res = 0
	for init in range(0, 10 ** 6 + 10):
		cur = init
		ok = True
		for i in range(len(s)):
			res = res + 1
			if s[i] == '+':
				cur = cur + 1
			else:
				cur = cur - 1
			if cur < 0:
				ok = False
				break
		if ok:
			break
	return res
t = int(input())
for _ in range(t):
	s = stdin.readline().strip()
	(plus, minus) = (0, 0)
	plustreak = 0
	n = len(s)
	i = 0
	res = 0
	while i < n:
		if s[i] == '+':
			res += 1
			plus += 1
			plustreak += 1
		else:
			minus += 1
			if i > 0 and s[i - 1] == '+':
				res += 1
			elif plus >= minus:
				res += 1
			elif plustreak:
				res += 1
			else:
				res += i + 1 + 1
			plustreak = max(0, plustreak - 1)
		i += 1
	print(res)


import sys

def answer(s):
	res = 0
	summ = 0
	for i in range(len(s)):
		if s[i] == '+' and summ >= 0:
			summ += 1
		elif s[i] == '+' and summ < 0:
			summ = 1
		else:
			summ -= 1
		if summ >= 0:
			res += 1
		else:
			res += 1 + (i + 1)
	return res

def main():
	t = int(input())
	while t:
		s = sys.stdin.readline().rstrip()
		print(answer(s))
		t -= 1
	return
main()


for _ in range(int(input())):
	l = input()
	i = 0
	ans = 0
	f = 0
	cnt = 0
	while i < len(l):
		if l[i] == '+':
			cnt += 1
		else:
			cnt -= 1
		if cnt < 0:
			ans += i + 1
			cnt = 0
			if f == 0:
				f = 1
		i += 1
	print(ans + len(l))


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	s = input()
	a = list()
	curr = 0
	for i in s:
		if i == '+':
			curr += 1
		else:
			curr -= 1
		a.append(curr)
	n = len(s)
	res = n
	ch = 1
	ct = -1
	for i in range(n):
		if a[i] == ct:
			res += i + 1
			ct -= 1
	print(res)


test_case = int(input())
for _ in range(test_case):
	st = input()
	cur = 0
	a = []
	for i in range(len(st)):
		if st[i] == '+':
			cur += 1
		else:
			cur -= 1
		a.append(cur)
	res = 0
	min = 0
	for i in range(len(a)):
		if min > a[i]:
			res += i + 1
			min = a[i]
	res += len(a)
	print(res)


from sys import stdin
input = stdin.readline
INF = 10 ** 9 + 7
MAX = 10 ** 7 + 7
MOD = 10 ** 9 + 7
for Ti in range(int(input().strip())):
	s = input().strip()
	ans = 0
	cs = 0
	slen = len(s)
	for i in range(slen):
		if s[i] == '-':
			cs -= 1
		else:
			cs += 1
		if cs < 0:
			ans += i + 1
			cs += 1
	ans += slen
	print(ans)


t = int(input())
for i in range(t):
	s = list(input())
	cur = 0
	total = 0
	final = 0
	for j in range(len(s)):
		if s[j] == '-':
			total -= 1
		else:
			total += 1
		if cur + total < 0:
			cur += 1
			final += j + 1
	print(final + len(s))


for _ in range(int(input())):
	s = input()
	l = 0
	curr = 0
	arr = [0]
	for i in range(len(s)):
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if 1 - curr > len(arr):
			arr.append(i + 1)
	print(sum(arr) + len(s))


for _ in range(int(input())):
	s = input()
	st = []
	n = len(s)
	cur = 0
	res = 0
	for i in range(n):
		if s[i] == '+':
			cur += 1
			st.append(s[i])
		else:
			cur += 1
			if st:
				st.pop()
			else:
				res += cur
	print(res + cur)


tc = int(input())
for ctr in range(tc):
	s = input()
	(cur, mn, res) = (0, 0, len(s))
	for i in range(len(s)):
		cur += 1 if s[i] == '+' else -1
		if cur < mn:
			mn = cur
			res += i + 1
	print(res)


for _ in range(int(input())):
	s = input()
	(ans, bal, m) = (0, 0, 0)
	for i in range(len(s)):
		if s[i] == '+':
			bal += 1
		else:
			bal -= 1
		if bal < 0:
			ans += i + 1
			bal = 0
	ans += len(s)
	print(ans)


for i in range(int(input())):
	s = list(input())
	res = 0
	n = 0
	arr = []
	for i in range(len(s)):
		if s[i] == '+':
			n += 1
		else:
			n -= 1
		arr.append(n)
	needInit = -min(arr)
	if needInit <= 0:
		print(len(s))
	else:
		t = 0
		initNow = 0
		for i in range(len(s)):
			if 0 > initNow + arr[i]:
				t += (i + 1) * (abs(arr[i]) - initNow)
				initNow += abs(arr[i]) - initNow
		print(t + len(s))


t = int(input())
for i in range(t):
	s = input()
	l = []
	count = 0
	ans = 0
	tmp = -1
	for j in range(len(s)):
		if s[j] == '-':
			count = count - 1
		else:
			count = count + 1
		l.append(count)
	count = 1
	for j in l:
		if j == tmp:
			ans = ans + count
			tmp = tmp - 1
		count = count + 1
	print(ans + len(s))


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
a = [list(input()) for i in range(n)]
for i in range(n):
	ans = 0
	cnt = 0
	for j in range(len(a[i])):
		ans += 1
		if a[i][j] == '+':
			cnt += 1
		else:
			cnt -= 1
			if cnt < 0:
				cnt = 0
				ans += j + 1
	print(ans)


for test in range(int(input())):
	s = input()
	res = 0
	sa = []
	curr = 0
	for i in s:
		if i == '+':
			curr += 1
		else:
			curr -= 1
		sa.append(curr)
	sad = {}
	for i in range(len(s) - 1, -1, -1):
		sad[sa[i]] = i
	ans = False
	pos = 0
	while True:
		if -pos - 1 in sad:
			res += sad[-pos - 1] + 1
		else:
			res += len(s)
			break
		pos += 1
	print(res)


for _ in range(int(input())):
	s = str(input())
	put = 0
	check = 1
	ans = len(s)
	for i in range(len(s)):
		if s[i] == '+':
			put += 1
		else:
			put += -1
		if put == -check:
			check += 1
			ans += i + 1
	print(ans)


def main():
	for case in range(int(input())):
		s = input().strip()
		cum_sum = 0
		min_cum_sum = 0
		result = len(s)
		for (i, c) in enumerate(s):
			cum_sum += 1 if c == '+' else -1
			if cum_sum < min_cum_sum:
				result += i + 1
				min_cum_sum = cum_sum
		print(result)
main()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def instr():
	return str(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(map(int, list(s[:len(s) - 1])))

def invr():
	return map(int, input().split())
from collections import Counter

def main():
	t = inp()
	for _ in range(t):
		s = instr()[:-1]
		dic = {}
		a = 0
		for (i, c) in enumerate(s):
			if c == '+':
				a += 1
			else:
				a -= 1
				if a < 0 and a not in dic:
					dic[a] = i
		res = len(s)
		for (k, v) in dic.items():
			res += v + 1
		print(res)
main()


t = int(input())
while t > 0:
	t = t - 1
	s = input()
	res = 0
	prefixsum = []
	if s[0] == '-':
		prefixsum.append(-1)
	else:
		prefixsum.append(1)
	k = 0
	for i in range(1, len(s)):
		if s[i] == '-':
			temp = prefixsum[k] - 1
			prefixsum.append(temp)
			k += 1
		else:
			temp = prefixsum[k] + 1
			prefixsum.append(temp)
			k += 1
	i = 0
	curr = 0
	while i < len(prefixsum):
		if prefixsum[i] == -1 * curr - 1:
			res += i + 1
			curr += 1
			i += 1
		else:
			i += 1
	if prefixsum[i - 1] != -1 * curr - 1:
		res += len(prefixsum)
	print(res)


def calc(s):
	cum = 0
	low = 0
	out = len(s)
	for (i, c) in enumerate(s):
		if c == '+':
			cum += 1
		else:
			cum -= 1
		if cum < low:
			out += i + 1
			low = cum
	return out
for _ in range(int(input())):
	print(calc(input()))


n = int(input())
while n > 0:
	s = input()
	res = 0
	cur = 0
	tmp = 0
	for i in range(len(s)):
		res += 1
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			cur = 0
			res = res + i + 1
	print(res)
	n -= 1


t = int(input())
while t:
	t += -1
	s = input()
	tmp = 0
	l = []
	for i in s:
		if i == '+':
			tmp -= -1
		else:
			tmp += -1
		l.append(tmp)
	mn = min(l)
	ans = 0
	tmp = -1
	for i in range(len(l)):
		if l[i] == tmp:
			ans += i + 1
			tmp += -1
		if tmp < mn:
			break
	print(ans + len(s))


t = int(input())
for i in range(t):
	s = str(input())
	c = 0
	d = 0
	l = []
	for j in range(len(s)):
		if s[j] == '+':
			c += 1
		else:
			c -= 1
		if c < d:
			d = c
			l.append(j + 1)
	f = len(s)
	for j in range(len(l)):
		f += l[j]
	print(f)


import sys
import math
read = lambda : sys.stdin.readline()
T = int(read())
for t in range(T):
	s = read()
	arr = [0]
	for i in range(len(s)):
		if s[i] == '+':
			arr.append(arr[-1] + 1)
		elif s[i] == '-':
			arr.append(arr[-1] - 1)
	mn = 0
	result = 0
	for i in range(1, len(arr)):
		if arr[i] < mn:
			mn = arr[i]
			result += i
	result += len(arr) - 1
	print(result)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
entries = inp()
for i in range(entries):
	s = insr()
	res = 0
	n = 0
	tmp = 0
	for i in range(len(s)):
		if s[i] == '-':
			n -= 1
			if n < 0:
				res += i + 1
				n += 1
		else:
			n += 1
	res += len(s)
	print(res)


t = int(input())
for _ in range(t):
	s = input()
	ls = [0]
	for i in s:
		if i == '-':
			ls.append(ls[-1] - 1)
		else:
			ls.append(ls[-1] + 1)
	mi = min(ls)
	if mi >= 0:
		print(len(s))
	else:
		ans = 0
		count = 0
		se = set()
		for i in range(len(ls) - 1):
			if ls[i] > ls[i + 1] and ls[i + 1] < 0 and (ls[i + 1] not in se):
				se.add(ls[i + 1])
				ans += i + 1
				count += 1
		mi = abs(mi) + 1
		if mi > count:
			ans += len(s)
		print(ans)


def solve():
	s = input()
	(cur, cnt, res) = (0, -1, 0)
	for i in range(len(s)):
		if s[i] == '-':
			cur -= 1
		elif s[i] == '+':
			cur += 1
		if cur == cnt:
			res += i + 1
			cnt -= 1
	res += len(s)
	print(res)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	s = input()
	dic = {}
	(cnt, sl, mv) = (0, len(s), len(s))
	for i in range(sl):
		cnt += 1 if s[i] == '+' else -1
		mv = min(mv, cnt)
		dic[cnt] = min(dic.get(cnt, sl), i)
	if mv >= 0:
		print(sl)
	else:
		ans = 0
		for i in range(-1, mv - 1, -1):
			ans += dic.get(i) + 1
		print(ans + sl)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input().strip()
	n = len(s)
	ac = [0] * (n + 1)
	for i in range(1, n + 1):
		ac[i] = ac[i - 1] + (1 if s[i - 1] == '+' else -1)
	pos = 1
	ans = 0
	t = 0
	while pos <= n:
		while pos <= n and ac[pos] >= t:
			pos += 1
		ans += pos
		t -= 1
	print(ans - 1)


for _ in range(int(input())):
	s = input()
	posis = []
	count_of_neg = 0
	su = 0
	for i in range(len(s)):
		e = s[i]
		if e == '+':
			su += 1
		else:
			su -= 1
		if su == -1:
			su = 0
			posis.append(i + 1)
			count_of_neg += 1
	print(sum(posis) + len(s))


def solve(s):
	sm = 0
	init = 0
	cur = 0
	for i in range(len(s)):
		sm += 1
		if s[i] == '-':
			cur -= 1
		if s[i] == '+':
			cur += 1
		if init + cur < 0:
			sm += (i + 1) * abs(init + cur)
			init += abs(init + cur)
	print(sm)

def main():
	for _ in range(int(input())):
		s = str(input())
		solve(s)
main()


outputs = []
for __ in range(int(input())):
	A = input()
	sum_so_far = 0
	curr = 0
	curr_arr = []
	curr_arr.append(0)
	if A[0] == '+':
		sum_so_far += 1
	else:
		sum_so_far -= 1
	if len(A) == 1:
		if sum_so_far < 0:
			curr_arr.append(1)
	for (i, j) in enumerate(A[1:]):
		if sum_so_far + curr < 0:
			curr_arr.append(curr + 1)
			curr += 1
		else:
			curr_arr.append(curr)
		if j == '+':
			sum_so_far += 1
		else:
			sum_so_far -= 1
		if i + 1 == len(A) - 1:
			if sum_so_far + curr < 0:
				curr_arr.append(curr + 1)
	prev = None
	tot = 0
	for (i, j) in enumerate(curr_arr[0:len(A)]):
		if prev is None:
			prev = j
		elif prev != j:
			tot += i
			prev = j
		if i == len(A) - 1:
			tot += len(A)
	if len(curr_arr) > len(A):
		tot += len(A)
	print(tot)


def main():
	t = int(input())
	for _ in range(t):
		s = list(str(input()))
		n = len(s)
		cum = [0] * (n + 1)
		for i in range(n):
			if s[i] == '-':
				cum[i + 1] = cum[i] - 1
			else:
				cum[i + 1] = cum[i] + 1
		used = set()
		res = 0
		for i in range(1, n + 1):
			if cum[i] < 0:
				if cum[i] not in used:
					res += i
					used.add(cum[i])
		else:
			res += n
		print(res)
main()


def main():
	for _ in range(int(input())):
		s = input()
		(res, curr, now) = (0, 0, 0)
		for i in range(len(s)):
			if s[i] == '+':
				curr += 1
			else:
				curr -= 1
			if curr < now:
				res += i + 1
				now = curr
		res += len(s)
		print(res)
main()


for i in range(int(input())):
	s = input()
	k = 0
	res = 0
	for i in range(len(s)):
		if s[i] == '-':
			if k == 0:
				res = res + i + 2
			else:
				res = res + 1
				k = k - 1
		else:
			res = res + 1
			k = k + 1
	print(res)


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
import io, os
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().strip().split()))
rls = lambda : list(map(str, input().split()))
t = int(input())
for _ in range(0, t):
	a = list(input().strip())
	d = defaultdict(lambda : 0)
	ans = 0
	c = 0
	for i in range(0, len(a)):
		if a[i] == '-':
			c = c - 1
			if d[c] == 0 and c < 0:
				d[c] = 1
				ans = ans + i + 1
		else:
			c = c + 1
	ans = ans + len(a)
	print(ans)


for _ in range(int(input())):
	s = input()
	n = len(s)
	ans = n
	tmp = 0
	for i in range(n):
		if s[i] == '+':
			tmp += 1
		elif tmp > 0:
			tmp -= 1
		else:
			ans += i + 1
	print(ans)


import sys
from sys import stdin, stdout
from collections import Counter
t = int(stdin.readline().strip())
for _ in range(t):
	s = stdin.readline().strip()
	ctr = 0
	res = 0
	ind = 0
	for i in range(len(s)):
		if s[i] == '+':
			ctr += 1
		else:
			ctr -= 1
		if ctr < res:
			res = ctr
			ind += i + 1
	ind += len(s)
	stdout.write(str(ind) + '\n')


n = int(input())
for _ in range(n):
	s = input()
	(total, ans) = (0, 0)
	for i in range(len(s)):
		if s[i] == '-':
			total -= 1
		else:
			total += 1
		if total < 0:
			ans += i + 1
			total = 0
	print(ans + len(s))


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n
avl = AvlTree()

class SegmentTree1:

	def __init__(self, data, default='z', func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for i in range(int(input())):
	s = input()
	b = [0] * len(s)
	c = 0
	n = len(s)
	for i in range(n):
		if s[i] == '-':
			c -= 1
		else:
			c += 1
		b[i] = c
	ans = 0
	c = 0
	for i in range(n):
		if b[i] < c:
			ans += i + 1
			c -= 1
	print(ans + len(s))


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = int(input())
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	s = insr()
	n = len(s)
	first = {}
	total = 0
	curr = 0
	for i in range(n):
		if s[i] == '+':
			total += 1
		else:
			total -= 1
		if total < curr:
			first[-total] = i + 1
			curr = total
	curr = -curr
	ans = n
	for i in range(curr):
		ans += first[i + 1]
	print(ans)


t = int(input())

def f(q):
	if q == '+':
		return 1
	return -1
from math import *
for ty in range(t):
	n = input()
	sums = [0] * len(n)
	sums[0] = f(n[0])
	sq = {}
	sq[sums[0]] = 0
	sl = set()
	sl.add(sums[0])
	for i in range(1, len(n)):
		cl = -1
		if n[i] == '+':
			cl = 1
		sums[i] = sums[i - 1] + cl
		if sums[i] not in sl:
			sq[sums[i]] = i
		sl.add(sums[i])
	cur = 0
	res = 0
	rq = min(sums)
	while cur < -1 * rq:
		res += abs(sq[-1 * cur - 1]) + 1
		cur += 1
	print(res + len(n))


t = int(input())
for _ in range(t):
	s = input()
	cumSum = []
	ind = []
	for i in range(len(s)):
		if i == 0:
			if s[i] == '+':
				cumSum.append(1)
				ind.append(1)
			else:
				cumSum.append(-1)
				ind.append(-1)
		else:
			temp = cumSum[-1]
			if s[i] == '+':
				cumSum.append(1 + temp)
			else:
				cumSum.append(-1 + temp)
			ind.append(cumSum[i])
	f = {}
	for i in range(len(ind) - 1, -1, -1):
		f[ind[i]] = i + 1
	count = 0
	for i in range(1, 10 ** 6 + 4):
		try:
			count += f[-i]
		except KeyError:
			count += len(s)
			break
	print(count)


import math
import sys
for _ in range(int(input())):
	s = input()
	(r, c) = (0, 0)
	ans = len(s)
	for i in range(len(s)):
		if s[i] == '+':
			r += 1
		else:
			c += 1
		if c > r:
			ans += i + 1
			c -= 1
	print(ans)


def hel(s):
	n = len(s)
	l = [0] * n
	if s[0] == '-':
		l[0] = -1
	else:
		l[0] = 1
	for i in range(1, n):
		if s[i] == '-':
			l[i] = l[i - 1] - 1
		else:
			l[i] = l[i - 1] + 1
	bar = min(l)
	if bar >= 0:
		return n
	else:
		bar = -1 * bar
	c = 0
	for i in range(n):
		if l[i] < 0:
			p = -1 * l[i]
			p -= c
			if p < 0:
				l[i] = 0
			else:
				c += p
				l[i] = p
		else:
			l[i] = 0
	u = 0
	for i in range(n):
		u += l[i] * (i + 1)
	return u + n
t = int(input())
for i in range(t):
	s = input()
	print(hel(s))


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x))

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 9 + 7

def solve():
	s = input()
	n = len(s)
	pref = [0] * n
	cur = 0
	for i in range(n):
		if s[i] == '-':
			cur -= 1
		else:
			cur += 1
		pref[i] = cur
	inf = max(pref)
	last = 0
	sm = 0
	for i in range(n):
		if pref[i] < 0:
			x = pref[i] * -1
			if last < x:
				sm += (i + 1) * (x - last)
				last = x
	print(sm + (i + 1))
t = II()
for i in range(t):
	solve()


for x in range(int(input())):
	s = input()
	k = 0
	cnt = 0
	tot = 0
	cur = 0
	for x in range(len(s)):
		if s[x] == '+':
			k += 1
			cnt += 1
		else:
			k -= 1
			cnt += 1
		if k < 0:
			cnt = cnt + x + 1
			k += 1
	print(cnt)


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	s = getStr()
	maxK0 = 0
	res = 0
	k0 = 0
	p = []
	for i in range(len(s)):
		p.append(maxK0)
		if s[i] == '-':
			k0 += 1
		else:
			k0 -= 1
		maxK0 = max(maxK0, k0)
	for i in range(len(p)):
		res += maxK0 - p[i] + 1
	print(res)


inp = lambda : int(input())
inpm = lambda : map(int, input().split())
inpl = lambda : list(inpm())
l2mn = lambda _n, _m: [[0 for __ in range(_m)] for _ in range(_n)]
l2n = lambda _n: l2mn(_n, _n)
INF = int(1e+18)
MOD = int(1000000000.0) + 7
N = 2000009

def solve():
	s = input()
	n = len(s)
	a = [0] * (n + 1)
	res = [0] * (n + 1)
	k = 0
	m = 0
	for i in range(1, n + 1):
		if s[i - 1] == '-':
			a[i] = a[i - 1] + 1
		else:
			a[i] = a[i - 1] - 1
		if a[i] > m:
			m = a[i]
			for j in range(k, m):
				res[j] = i
			k = m
		if i == n:
			for j in range(k, m + 1):
				res[j] = i
	print(sum(res))

def main():
	t = inp()
	for i in range(t):
		solve()
main()


t = int(input())
for _ in range(t):
	arr = input()
	n = len(arr)
	curr = 0
	score = n
	i = 0
	while i < n:
		if arr[i] == '+':
			i += 1
			curr += 1
		else:
			i += 1
			curr -= 1
		if curr < 0:
			i -= 1
			while i < n and arr[i] == '-':
				i += 1
				score += i
			curr = 0
	print(score)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(s):
	result = 0
	curr = 0
	target = 0
	for i in range(len(s)):
		curr -= s[i]
		if curr > target:
			result += (i + 1) * (curr - target)
			target = curr
	result += len(s)
	return result
for i in tests():
	s = [1 if x == '+' else -1 for x in str_in()]
	out(solve(s))


for _ in range(int(input())):
	a = input()
	res = 0
	c = 0
	for i in range(len(a)):
		if a[i] == '+':
			c += 1
		else:
			c -= 1
		if c < 0:
			c = 0
			res += i + 1
	print(res + len(a))


def p(s):
	res = 0
	best = 0
	cur = 0
	ans = len(s)
	for i in range(len(s)):
		res += 1
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < best:
			ans += i + 1
			best = cur
	return ans
for t in range(int(input())):
	s = input().strip()
	print(p(s))


from sys import stdin, stdout
import sys
from math import *

def b(ar, n):
	l = 0
	r = len(ar) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if ar[m][0] < n:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans
for __ in range(int(input())):
	s = input()
	d = {}
	a = 0
	for i in range(len(s)):
		if s[i] == '+':
			a += 1
		else:
			a -= 1
		if d.get(a) == None:
			d[a] = i + 1
	ar = []
	for i in d:
		ar.append([i, d[i]])
	ar.sort()
	x = 0
	rslt = 0
	while 1:
		ans = b(ar, x)
		if ans == -1:
			rslt += len(s)
			break
		else:
			rslt += ar[ans][1]
		x -= 1
	print(rslt)


def main():
	t = int(input())
	for g in range(t):
		s = input()
		n = len(s)
		now_count = 0
		minimum = [0 for i in range(n)]
		for i in range(n):
			if s[i] == '+':
				now_count += 1
			else:
				now_count -= 1
			if i > 0:
				minimum[i] = minimum[i - 1]
			minimum[i] = max(minimum[i], -now_count)
		last = 0
		count = 0
		for i in range(n):
			if minimum[i] > last:
				count += i + 1
				last = minimum[i]
		count += n
		print(count)
main()


for _ in range(int(input())):
	s = input()
	res = 0
	n = 0
	c = 0
	num = 0
	for el in s:
		n += 1
		if el == '+':
			c += 1
		else:
			c -= 1
		if c + num < 0:
			res += n
			num += 1
	res += n
	print(res)


from sys import stdin, stdout
for test in range(int(stdin.readline())):
	s = stdin.readline()
	s = s[:-1]
	l = len(s)
	ans = 0
	count = 0
	i = 0
	while i < l:
		if s[i] == '-' and count == 0:
			ans += i + 1
		elif s[i] == '-' and count > 0:
			ans += 1
			count -= 1
		elif s[i] == '+' and count > 0:
			ans += 1
			count += 1
		else:
			ans += i + 1
			count += 2
		i += 1
	if s[-1] == '-' and count == 0:
		ans += l
	stdout.write(str(ans) + '\n')


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	s = stdin.readline().strip()
	(cur, res) = (0, 0)
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
			res += 1
		elif cur > 0:
			cur -= 1
			res += 1
		else:
			res += i + 2
	stdout.write('{}\n'.format(res))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	s = ri()
	lis = [0] * len(s)
	for i in range(len(s)):
		if i == 0:
			lis[i] = 1 if s[i] == '+' else -1
		else:
			lis[i] = lis[i - 1] + (1 if s[i] == '+' else -1)
	dic = {}
	for i in range(len(lis)):
		dic[lis[i]] = min(dic.get(lis[i], INF), i)
	ans = 0
	for i in range(1, len(s) + 2):
		if -i in dic:
			ans += dic[-i] + 1
		else:
			ans += len(s)
			break
	print(ans)


for _ in range(int(input())):
	s = input()
	cur = 0
	res = len(s)
	t = 0
	for (i, v) in enumerate(s):
		if v == '+':
			cur += 1
		else:
			cur -= 1
		if cur + t < 0:
			res += i + 1
			t += 1
	print(res)


t = int(input())
for i in range(t):
	soma = 0
	aux = 0
	cur = 0
	a = input()
	l = list(a)
	for aux in range(len(l)):
		if l[aux] == '-' and cur <= 0:
			soma += aux + 1
		if l[aux] == '+':
			cur += 1
		if l[aux] == '-' and cur > 0:
			cur -= 1
	print(soma + len(l))
	soma = 0


for i in range(int(input())):
	st = input()
	n = len(st)
	plus = 0
	minus = 0
	mis = 0
	ans = 0
	for i in range(n):
		if st[i] == '+':
			plus += 1
		else:
			minus += 1
		if minus > plus:
			ans += i + 1
			minus = plus
	print(ans + n)


T = int(input())
for t in range(T):
	s = list(input())
	l = len(s)
	cur = 0
	ans = 0
	for i in range(l):
		if s[i] == '+':
			cur += 1
		elif cur == 0:
			ans += i + 1
		else:
			cur -= 1
	ans += l
	print(ans)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	s = input()
	n = len(s) - 1
	cur = res = 0
	for i in range(n):
		cur += [-1, 1][s[i] == '+']
		if cur < 0:
			res += i + 1
			cur = 0
	print(res + n)


for _ in range(int(input())):
	s = input()
	(r, q) = (0, 0)
	l = len(s)
	for i in range(l):
		if s[i] == '-':
			r += 1
		else:
			q += 1
		if r > q:
			l += i + 1
			r -= 1
	print(l)


t = int(input())
while t:
	s = input()
	cur = res = 0
	i = 0
	n = len(s)
	while i < n:
		if s[i] == '+':
			cur += 1
			res += 1
		elif cur > 0:
			cur -= 1
			res += 1
		else:
			res += i + 2
		i += 1
	print(res)
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	res = 0
	cur = 0
	result = 0
	for i in s:
		res += 1
		if i == '+':
			cur += 1
		if i == '-':
			cur -= 1
		if cur < 0:
			result += res
			cur = 0
	print(res + result)


import sys
input = sys.stdin.readline
INF = 10 ** 9
T = int(input())
for _ in range(T):
	S = input().rstrip()
	N = len(S)
	min_index = [INF] * (N + 5)
	k = 0
	for i in range(N):
		if S[i] == '+':
			k += 1
		else:
			k -= 1
		if k < 0:
			min_index[-k] = min(min_index[-k], i)
	ans = N
	for i in range(N):
		if min_index[i + 1] == INF:
			break
		else:
			ans += min_index[i + 1] + 1
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	curr = 0
	j = 0
	f = 0
	total = 0
	count = 0
	count2 = 0
	for i in range(len(s)):
		if s[i] == '-':
			total += 1
			curr -= 1
			count += 1
			if curr < 0:
				j += 1
				curr = j - count + count2
				while curr < 0:
					j += 1
					curr = j - count + count2
				total += i + 1
		else:
			count2 += 1
			total += 1
			curr += 1
	print(total)


t = int(input())
for test in range(t):
	s = input()
	x = 0
	ans = len(s)
	p = m = 0
	for i in range(0, len(s)):
		if s[i] == '+':
			p += 1
		else:
			m += 1
		if m > p + x:
			ans += i + 1
			x += 1
	print(ans)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	s = inp()
	ans = len(s)
	curr = 0
	lowestCurr = 10 ** 9
	count = 1
	for i in s:
		if i == '+':
			curr += 1
		else:
			curr -= 1
		if curr < lowestCurr and curr < 0:
			ans += count
		lowestCurr = min(curr, lowestCurr)
		count += 1
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		s = input()
		print(f(s))

def f(s):
	hist = dict()
	min_cnt = 0
	cnt = 0
	for (i, c) in enumerate(s):
		if c == '+':
			cnt += 1
		else:
			cnt -= 1
		if cnt < 0 and cnt not in hist:
			hist[cnt] = i + 1
		min_cnt = min(min_cnt, cnt)
	if min_cnt >= 0:
		return len(s)
	else:
		res = 0
		while min_cnt < 0:
			res += hist[min_cnt]
			min_cnt += 1
		return len(s) + res
main()


rr = lambda : input().strip()

def solve(s):
	(res, r) = (0, 0)
	for i in range(len(s)):
		if s[i] == '-':
			r -= 1
			if r < 0:
				res += i + 1
				r += 1
		elif s[i] == '+':
			r += 1
	res += len(s)
	return res
T = int(rr())
for _ in range(T):
	s = rr()
	ans = solve(s)
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	add = res = 0
	seen = set()
	for (i, c) in enumerate(s, 1):
		add += 1 if c == '+' else -1
		if add < 0 and add not in seen:
			res += i
		seen.add(add)
	print(res + n)


t = int(input())
for _ in range(t):
	s = input()
	cnt = 0
	ind = 0
	flag = True
	for i in range(len(s)):
		if s[i] == '+':
			cnt += 1
		else:
			cnt -= 1
		if cnt < 0:
			flag = False
			ind += i + 1
			cnt += 1
	if flag:
		print(len(s))
	else:
		print(ind + len(s))


def solve():
	s = input()
	dif = 0
	res = 0
	mini = -1
	for i in range(len(s)):
		if s[i] == '+':
			dif += 1
		else:
			dif -= 1
		if dif <= mini:
			mini -= 1
			res += i + 1
	print(res + len(s))
t = int(input())
for _ in range(t):
	solve()


for x in range(int(input())):
	s = input()
	res = 0
	cur = 0
	init = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur = cur + 1
		else:
			cur = cur - 1
		if cur + init < 0:
			res += i + 1
			init += 1
	res += len(s)
	print(res)


for t in range(int(input())):
	s = input()
	tt = len(s)
	lis = {}
	(p, m) = (0, 0)
	maxim = 0
	for i in range(tt):
		if s[i] == '+':
			p += 1
		else:
			m += 1
		if m - p >= 0 and m - p not in lis:
			lis[m - p] = i + 1
			maxim = max(maxim, m - p)
	lim = len(lis)
	if lim:
		res = 0
		x = 0
		while x - maxim <= 0:
			cur = x
			try:
				res += lis[x + 1]
			except:
				res += tt
			x += 1
		print(res)
	else:
		print(tt)


for _ in range(int(input())):
	s = input()
	ans = [0]
	answer = len(s)
	mn = 0
	for i in range(len(s)):
		if s[i] == '+':
			ans.append(ans[-1] + 1)
		else:
			ans.append(ans[-1] - 1)
		if ans[-1] < mn:
			answer += i + 1
			mn = ans[-1]
	print(answer)


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def process():
	(res, cur) = (0, 0)
	s = stin()
	for j in range(0, len(s), 1):
		if s[j] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			res += j + 1
			cur = 0
	print(res + len(s))
for _ in range(inin()):
	process()


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		s = input().strip()
		res = 0
		mx = 1
		curr = 0
		for i in range(len(s)):
			c = s[i]
			if c == '+':
				curr -= 1
			else:
				curr += 1
				if curr == mx:
					res += i + 1
					mx += 1
		res += len(s)
		print(res)
prog()


t = int(input())

def pam(s):
	res = 0
	cur = 0
	j = 1
	for i in s:
		res += 1
		if i == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			cur = 0
			res = res + j
		j += 1
	return res
li = []
for i in range(t):
	li = li + [input()]
for i in li:
	print(pam(i))


t = int(input())
for k in range(t):
	s = input()
	plus = s.count('+')
	minus = s.count('-')
	x = plus - minus
	sum = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '+':
			sum += 1
		else:
			sum -= 1
		if sum < 0:
			sum = 0
			ans += i + 1
	print(ans + len(s))


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	c = 0
	v = [0] * n
	if n == 1 and s[0] == '-':
		print('2')
	else:
		for i in range(n):
			if s[i] == '-':
				c += 1
				v[i] = c
			else:
				c -= 1
				v[i] = c
		init = 0
		k = 0
		res = 0
		i = 0
		while True:
			i = k
			while i < n:
				if i == k:
					res += k + 1
				else:
					res += 1
				if v[i] > init:
					break
				k = i
				i += 1
			init += 1
			if k == n - 1:
				break
		print(res)


def mii():
	return map(int, input().split())
for _ in range(int(input())):
	a = list(input())
	n = len(a)
	s = 0
	ms = 0
	for i in range(n):
		if a[i] == '+':
			a[i] = 1
		else:
			a[i] = -1
		s += a[i]
		ms = min(s, ms)
		a[i] = s
	(i, j) = (0, 0)
	ans = 0
	while i <= n:
		while j < n and i + a[j] >= 0:
			j += 1
		if j == n:
			ans += j
			break
		ans += j + 1
		i += 1
	print(ans)


for _ in range(int(input())):
	s = input()
	tmp = set()
	(t, m) = (0, {})
	for (i, c) in enumerate(s):
		if c == '-':
			t -= 1
		else:
			t += 1
		if t not in m:
			m[t] = i + 1
		if t < 0:
			tmp.add(t)
	ans = len(tmp)
	res = len(s)
	for i in range(1, ans + 1):
		res += m[-i]
	print(res)


def main():
	t = int(input())
	for _ in range(t):
		s = input()
		res = 0
		cur = 0
		for (c, el) in enumerate(s):
			res += 1
			if el == '+':
				cur += 1
			else:
				cur -= 1
				if cur == -1:
					cur += 1
					res += c + 1
		print(res)
main()


n = int(input())
for m in range(n):
	res = 0
	s = input()
	cur = 0
	mini = 0
	score = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < mini:
			mini = cur
			score += i + 1
	print(score + len(s))


inputn = int(input())
ans = []
for i in range(inputn):
	c = input()
	l = len(c)
	res = 0
	t = 0
	for k in range(l):
		j = c[k]
		if j == '-':
			t = t - 1
		else:
			t = t + 1
		if t < 0:
			res = res + k + 1
			t = 0
	res = res + l
	ans.append(res)
for i in ans:
	print(i)


for _ in range(int(input())):
	st = input()
	(curr, mx) = (0, 0)
	ans = 0
	for i in range(len(st)):
		if st[i] == '-':
			curr += 1
		else:
			curr -= 1
		if curr > mx:
			ans += i + 1
		mx = max(mx, curr)
	ans += len(st)
	print(ans)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	s = input().strip()
	x = 0
	r = [0] * len(s)
	for i in range(len(s)):
		if s[i] == '+':
			x += 1
		else:
			x -= 1
		r[i] = x
	k = min(r)
	if k >= 0:
		print(len(s))
	else:
		r = -k
		p = 0
		an = x = 0
		for i in range(len(s)):
			if s[i] == '+':
				x += 1
			else:
				x -= 1
			if x < p:
				an += i + 1
				p -= 1
		print(an + len(s))


t = int(input())
for i in range(t):
	s = input()
	total = 0
	val = 0
	for i in range(len(s)):
		if s[i] == '-':
			total -= 1
		else:
			total += 1
		if total < 0:
			val += i + 1
			total = 0
	print(val + len(s))


t = int(input())
while t > 0:
	t -= 1
	x = input()
	now = 0
	plus = 0
	for i in range(len(x)):
		if x[i] == '-':
			if plus != 0:
				plus -= 1
			else:
				now += 1
		else:
			plus += 1
	now += 1
	plus = 0
	res = 0
	for i in range(len(x)):
		res += now
		if x[i] == '-':
			if plus != 0:
				plus -= 1
			else:
				now -= 1
		else:
			plus += 1
	print(res)


T = int(input())
for t in range(T):
	s = input()
	res = 0
	init = 0
	for i in range(len(s)):
		if s[i] == '+':
			init += 1
		else:
			init -= 1
		if init < 0:
			res += i + 1
			init += 1
	res += len(s)
	print(res)


t = int(input())
for _ in range(t):
	st = input()
	add = 0
	sub = 0
	list1 = []
	list1.append(-1)
	cutoff = 0
	max = 0
	for i in range(len(st)):
		sym = st[i]
		if sym == '+':
			add += 1
		else:
			sub += 1
		if sub - add > cutoff:
			max = sub - add
			list1.append(i)
			cutoff += 1
	list1.append(len(st) - 1)
	ans = 0
	min = 0
	for i in range(1, len(list1)):
		size = max - min + 1
		quan = list1[i] - list1[i - 1]
		ans += size * quan
		min += 1
	print(ans)


import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def solve(n, d):
	pass

def main():
	for _ in range(iin()):
		s = sin()
		cp = 0
		cm = 0
		x = 0
		mini = MAX
		d = {}
		res = 0
		for i in range(len(s)):
			if s[i] == '+':
				x += 1
			else:
				x -= 1
			mini = min(mini, x)
			if x not in d:
				d[x] = i
		for i in range(mini, 0, 1):
			res += d[i] + 1
		print(res + len(s))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	s = input()
	c = 0
	q = 0
	ans = 0
	t = len(s)
	for x in range(t):
		if s[x] == '+':
			c += 1
		if s[x] == '-':
			c -= 1
		if c < q:
			ans += x + 1
			q = c
	ans += t
	print(ans)


t = int(input())
for you in range(t):
	res = 0
	s = input()
	n = len(s)
	curr = 0
	for i in range(n):
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < 0:
			res += i + 1
			curr = 0
	print(res + n)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	s = is1()
	cur = res = 0
	for i in range(len(s)):
		res += 1
		if s[i] == '-':
			cur -= 1
		else:
			cur += 1
		if cur < 0:
			cur = 0
			res += i + 1
	print(res)


def value(s):
	leng = len(s)
	l = [0] * (leng + 1)
	res = leng
	d = set()
	for i in range(leng):
		if s[i] == '+':
			l[i + 1] = l[i] + 1
		else:
			l[i + 1] = l[i] - 1
			if l[i + 1] < 0 and l[i + 1] not in d:
				d.add(l[i + 1])
				res += i + 1
	print(res)
for _ in range(int(input())):
	value(input())


T = int(input())
for _ in range(T):
	N = input()
	cur = 0
	res = 0
	for i in range(1, len(N) + 1):
		if N[i - 1] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			res += i + 1
			cur = 0
		else:
			res += 1
	print(res)


def solve(s):
	diff = 0
	cnt = len(s)
	for (i, c) in enumerate(s):
		diff += 1 if c == '+' else -1
		if diff < 0:
			diff = 0
			cnt += i + 1
	return cnt
t = int(input())
for i_t in range(t):
	s = input()
	print(solve(s))


t = int(input())
for _ in range(t):
	s = str(input())
	res = 0
	d = 0
	h = 0
	for i in range(len(s)):
		if s[i] == '+':
			d += 1
		else:
			d -= 1
		if d < 0:
			if h >= -d:
				res += 1
			else:
				res += 1
				res += (-d - h) * (i + 1)
				h = -d
		else:
			res += 1
	print(res)


def oki(s):
	res = len(s)
	(cur, mn) = (0, 0)
	for i in range(len(s)):
		cur += 1 if s[i] == '+' else -1
		if cur < mn:
			mn = cur
			res += i + 1
	print(res)
for _ in range(int(input())):
	s = str(input())
	oki(s)


for _ in range(int(input())):
	arr = list(input())
	n = len(arr)
	fix = 1
	mis = 0
	plus = 0
	ans = 0
	for i in range(n):
		if arr[i] == '-':
			if plus > 0:
				plus -= 1
				continue
			else:
				ans += i + 1
		if arr[i] == '+':
			plus += 1
			continue
	ans += n
	print(ans)


t = int(input())
for _ in range(t):
	mp = {'+': 1, '-': -1}
	a = [mp[c] for c in input()]
	(cumsum, currmincumsum, ans) = (0, 0, 0)
	for i in range(len(a)):
		cumsum += a[i]
		if cumsum < currmincumsum:
			ans += i + 1
			currmincumsum = cumsum
	ans += len(a)
	print(ans)


import sys
import math
from collections import Counter
from operator import itemgetter
import queue

def IO():
	sys.stdin = open('pyinput.txt', 'r')
	sys.stdout = open('pyoutput.txt', 'w')

def GCD(a, b):
	if b == 0:
		return a
	else:
		return GCD(b, a % b)

def LCM(a, b):
	return a * (b // GCD(a, b))

def scan(TYPE_1, TYPE_2=0):
	if TYPE_1 == int:
		return map(int, sys.stdin.readline().strip().split())
	elif TYPE_1 == float:
		return map(float, sys.stdin.readline().strip().split())
	elif TYPE_1 == list and TYPE_2 == float:
		return list(map(float, sys.stdin.readline().strip().split()))
	elif TYPE_1 == list and TYPE_2 == int:
		return list(map(int, ('0 ' + sys.stdin.readline()).strip().split()))
	elif TYPE_1 == str:
		return sys.stdin.readline().strip()
	else:
		print('ERROR!!!!')

def main():
	t = int(scan(str))
	while t > 0:
		s = scan(str)
		ans = 0
		res = 0
		cur = 0
		l = len(s)
		for i in range(l):
			res += 1
			if s[i] == '-':
				cur -= 1
			else:
				cur += 1
			if cur < 0:
				ans += res
				cur = 0
		ans += res
		print(ans)
		t -= 1
main()


tests = int(input())
for tst in range(tests):
	s = input()
	p = [0]
	for i in range(len(s)):
		if s[i] == '+':
			p.append(p[-1] + 1)
		else:
			p.append(p[-1] - 1)
	a = [0] * (len(s) + 1)
	for i in range(len(s) + 1):
		if p[i] < 0:
			v = -p[i]
			if a[v] == 0:
				a[v] = i
	ans = len(s) + sum(a)
	print(ans)


for _ in range(int(input())):
	st = input()
	cur = 0
	li = []
	for i in st:
		if i == '+':
			cur += 1
			li.append(cur)
		else:
			cur -= 1
			li.append(cur)
	ans = 0
	times = 0
	for i in range(len(li)):
		if times + li[i] < 0:
			ans += (i + 1) * (-li[i] - times)
			times = -li[i]
		ans += 1
	print(ans)


import math
t = int(input())
while t != 0:
	t -= 1
	s = input()
	lt = [0 for _ in range(len(s))]
	if s[0] == '-':
		lt[0] = -1
	else:
		lt[0] = +1
	for i in range(1, len(s)):
		if s[i] == '-':
			lt[i] = lt[i - 1] - 1
		else:
			lt[i] = lt[i - 1] + 1
	n = len(s)
	ans = 0
	j = 0
	temp = 0
	for i in range(n):
		j = temp
		while j < n and lt[j] + i >= 0:
			j += 1
		temp = j
		if j < n:
			ans += j + 1
		elif j == n:
			ans += n
			break
	if n - 1 + lt[-1] < 0:
		ans += n
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	arr = [0] * len(s)
	mini = 0
	sumi = 0
	for j in range(len(s)):
		if s[j] == '+':
			sumi = sumi + 1
		else:
			sumi = sumi - 1
		if sumi < mini:
			arr[-1 * sumi - 1] = j + 1
			mini = sumi
	ans = 0
	for j in range(0, -1 * mini):
		ans = ans + arr[j]
	print(ans + len(s))


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 10 ** 9 + 7

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k)))) % NUMBER
from collections import deque, defaultdict
import heapq
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def dfs(g, timeIn, timeOut, depths, parents):
	cnt = 0
	stack = [[1, 0, 0, 0]]
	while stack:
		(v, neig_i, parent, depth) = stack[-1]
		parents[v] = parent
		depths[v] = depth
		if neig_i == 0:
			timeIn[v] = cnt
			cnt += 1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i += 1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u, 0, v, depth + 1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
cnt = 0

@bootstrap
def dfs(v, adj, timeIn, timeOut, depths, parents, parent=0, depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt += 1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u, adj, timeIn, timeOut, depths, parents, v, depth + 1)
	timeOut[v] = cnt
	cnt += 1
	yield

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def solution(s):
	d = dict()
	s = [1 if x == '+' else -1 for x in s]
	sm = 0
	cnt = 0
	for i in range(len(s)):
		sm += s[i]
		if sm < 0 and sm not in d:
			d[sm] = i
			cnt += 1
	res = 0
	start = cnt
	for i in range(cnt):
		key = -i - 1
		res += d[key] + 1
		start -= 1
	return res + len(s)

def main():
	T = ri()
	for i in range(T):
		s = rs()
		x = solution(s)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


for _ in range(int(input())):
	s = input()
	ans = 0
	base = 0
	i = 0
	init = 0
	while init <= 1000001:
		cur = init
		ok = True
		temp = base
		while i < len(s):
			temp = temp + 1
			if s[i] == '+':
				cur = cur + 1
			else:
				cur = cur - 1
			if cur < 0:
				ans += temp
				base = temp
				cur += 1
				ok = False
			i += 1
		if ok:
			break
	if i == len(s):
		ans += len(s)
	print(ans)


t = int(input())
for k in range(t):
	n = input()
	l = len(n)
	ans = l
	a = [0 for i in range(l)]
	for i in range(l):
		if i == 0:
			a[i] = 1 if n[i] == '+' else -1
		elif n[i] == '+':
			if a[i - 1] >= 0:
				a[i] = a[i - 1] + 1
			else:
				a[i] = 1
		else:
			a[i] = a[i - 1] - 1
		if a[i] < 0:
			ans += i + 1
	print(ans)


import math
t = int(input())
for _ in range(t):
	s = input()
	arr = []
	ind = 0
	cur = 0
	for i in range(len(s)):
		if s[i] == '-':
			cur -= 1
			arr.append(cur)
		else:
			cur += 1
			arr.append(cur)
	val = min(arr)
	d = {}
	array = []
	for i in range(len(arr)):
		if arr[i] not in d:
			if arr[i] < 0:
				d[arr[i]] = 1
				array.append(i + 1)
	print(sum(array) + len(s))


for _ in range(int(input())):
	s = str(input())
	temp = 0
	n = 0
	smallest = 0
	nl = [0]
	for i in s:
		n += 1
		if i == '+':
			temp += 1
		else:
			temp -= 1
		if temp < smallest:
			nl.append(n)
			smallest = temp
	print(sum(nl) + len(s))


def solve():
	s = input()
	pm = 0
	cur = 0
	ans = len(s)
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
			if cur < pm:
				pm = cur
				ans += i + 1
	print(ans)
t = int(input())
for _ in range(t):
	solve()


import sys

def score(bits):
	balance = 0
	result = 0
	seen_balance = set()
	for i in range(len(bits)):
		sign = bits[i]
		if sign == '+':
			balance += 1
		else:
			balance -= 1
		if balance < 0:
			if balance not in seen_balance:
				result += i + 1
				seen_balance.add(balance)
	return result + len(bits)
for line in sys.stdin.readlines()[1:]:
	bits = line.rstrip()
	print(score(bits))


t = int(input())
for _ in range(t):
	s = list(input())
	ans = 0
	x = 0
	(m, p) = (0, 0)
	l = len(s)
	for i in range(l):
		if s[i] == '-':
			m += 1
		else:
			p += 1
		if x < m - p:
			x = m - p
			ans += i + 1
	ans += l
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	res = []
	cnt = 0
	re = 0
	l = -10 ** 7
	a = False
	for i in range(len(s)):
		if s[i] == '+':
			cnt += 1
		else:
			cnt -= 1
		if cnt < 0:
			if a:
				if l > cnt:
					l = cnt
					res.append(i + 1)
			else:
				a = True
				l = cnt
				res.append(i + 1)
	se = len(s) + sum(res)
	print(se)


import sys
import math
data = sys.stdin.readlines()
for i in range(int(data[0])):
	s = list(data[i + 1][:len(data[i + 1]) - 1])
	suma = 0
	init = 0
	res = len(s)
	for j in range(len(s)):
		if s[j] == '+':
			suma += 1
		else:
			suma -= 1
		if init + suma < 0:
			init += 1
			res += j + 1
	print(res)


try:
	for _ in range(int(input())):
		s = input()
		cap = 0
		res = 0
		for i in range(len(s)):
			if s[i] == '-':
				cap -= 1
			elif s[i] == '+':
				cap += 1
			if cap < 0:
				res += i + 1
				cap = 0
		if cap >= 0:
			res += len(s)
		print(res)
except:
	pass


t = int(input())
for _ in range(t):
	s = input()
	min_b = 0
	b = 0
	balance = [0] * len(s)
	left = {}
	for i in range(len(s)):
		if s[i] == '-':
			b -= 1
		else:
			b += 1
		balance[i] = b
		min_b = min(min_b, b)
		left[b] = i
	for i in range(len(balance)):
		left[balance[i]] = min(i, left[balance[i]])
	ans = 0
	for i in left.keys():
		if i < 0:
			ans += left[i] + 1
	ans += len(s)
	print(ans)


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 9
mod = 998244353
for t in range(int(data())):
	s = data()
	m = INF
	ind = 0
	cur = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < m:
			m = cur
			ind = i
	ans = 0
	cur = 0
	j = 0
	i = 0
	while i < len(s):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		while cur + j < 0:
			ans += i + 1
			j += 1
		if cur == m:
			break
		i += 1
	j -= 1
	if cur + j < 0:
		ans += -(cur + j + 1) * (i + 1)
	ans += len(s)
	out(ans)


T = int(input().rstrip())
for tt in range(T):
	s = input().rstrip()
	lst = [0] * len(s)
	init = 0
	res = 0
	for (ind, i) in enumerate(s):
		if i == '+':
			init += 1
			lst[ind] = init
		elif i == '-':
			init -= 1
			lst[ind] = init
		if init < 0:
			res += ind + 1
			init = 0
	res += len(s)
	print(res)


def solve(s, ans):
	res = 0
	cur = 0
	for i in range(len(s)):
		res += 1
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			cur += 1
			res += i + 1
	ans.append(res)

def main():
	t = int(input())
	ans = []
	for i in range(t):
		s = input()
		solve(s, ans)
	for i in ans:
		print(i)
main()


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	s = [i for i in input() if i != '\n']
	freq = []
	if s[0] == '-':
		freq.append(1)
	else:
		freq.append(-1)
	for i in range(1, len(s)):
		if s[i] == '-':
			freq.append(freq[-1] + 1)
		else:
			freq.append(freq[-1] - 1)
	maxa = max(freq)
	ans = len(s)
	count = 0
	for i in range(len(freq)):
		if freq[i] == count + 1:
			ans += i + 1
			count += 1
		if count == maxa:
			break
	sys.stdout.write(str(ans) + '\n')


for _ in range(int(input())):
	n = input()
	curr = 0
	ans = 0
	for i in range(len(n)):
		if n[i] == '-':
			curr -= 1
		else:
			curr += 1
		if curr < 0:
			ans += i + 1
			curr = 0
	print(ans + len(n))


t = int(input())
for i in range(t):
	s = input()
	n = 0
	temp = 0
	arr = []
	for i in s:
		n += 1
		if i == '+':
			temp += 1
		else:
			temp -= 1
		arr.append(temp)
	index = 0
	ans = 0
	for i in range(n):
		if arr[i] < 0:
			if abs(arr[i]) > index:
				index += 1
				ans += i + 1
	ans += n
	print(ans)


import math

def main():
	string = str(input())
	curr = 0
	dp = []
	tot = 0
	for i in range(len(string)):
		if string[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr + tot < 0:
			dp.append(i + 1)
			tot += 1
	ans = len(string) + sum(dp)
	print(ans)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


t = int(input())
for i in range(t):
	s = input()
	d = 0
	su = 0
	c = 0
	l = 0
	for j in s:
		d += 1
		if j == '-':
			c -= 1
		else:
			c += 1
		if c < 0:
			su += d
			c = 0
	if c >= 0:
		su += d
	else:
		s += d
	print(su)


t = int(input())
for u in range(t):
	s = input()
	sum1 = [0 for i in range(len(s))]
	cur = 0
	for i in range(len(s)):
		if s[i] == '-':
			cur -= 1
		else:
			cur += 1
		sum1[i] = cur
	res = 0
	pr = 0
	for i in range(len(s)):
		res += 1
		if sum1[i] < pr:
			res += (i + 1) * (pr - sum1[i])
			pr = sum1[i]
	print(res)


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	dp = [0] * (n + 1)
	j = 0
	i = 1
	while j < n:
		l = 0
		num = 0
		while j < n and l >= 0:
			if s[j] == '+':
				l = l + 1
				num = num + 1
				j = j + 1
			elif s[j] == '-':
				l = l - 1
				num = num + 1
				j = j + 1
		dp[i] = dp[i - 1] + num
		i = i + 1
	sumi = 0
	for i in dp:
		sumi = sumi + i
	if l < 0:
		sumi = sumi + n
	print(sumi)


from copy import *
from math import *
import sys
t = int(input())
for i in range(t):
	s = input()
	res = 0
	cur = 0
	res_old = 0
	DAD = 0
	for j in range(len(s)):
		res += 1
		DAD += 1
		if s[j] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			res += DAD
			cur = 0
	print(res)


t = int(input())
for _ in range(t):
	s = input() + '0'
	dolg = False
	zap = 0
	ans = 0
	for (i, el) in enumerate(s):
		if dolg:
			ans += i
			dolg = False
		if el == '+':
			ans += 1
			zap += 1
		elif el == '-':
			ans += 1
			if zap > 0:
				zap -= 1
			else:
				dolg = True
	print(ans)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	s = input()
	z = 0
	pa = [0]
	for i in s:
		if i == '+':
			pa.append(pa[-1] + 1)
		else:
			pa.append(pa[-1] - 1)
	ans = 0
	cur = 0
	for i in range(1, len(pa)):
		if cur + pa[i] < 0:
			z = abs(pa[i])
			ans += i * abs(cur + pa[i]) + 1
			cur += 1
		else:
			ans += 1
	print(ans)


t = int(input())
while t:
	s = input()
	(answ, curr, last) = (len(s), 0, 0)
	for i in range(len(s)):
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < last:
			last = curr
			answ += i + 1
	print(answ)
	t -= 1


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		charit = input()
		n = len(charit)
		ans = 0
		cur = 0
		pexist = False
		for i in range(n):
			if charit[i] == '-':
				if cur < 0:
					ans += i + 1
				else:
					ans += 1
				cur -= 1
			else:
				pexist = True
				if cur < 0:
					ans += i + 1
					cur = 1
				else:
					ans += 1
					cur += 1
			if i == n - 1 and cur < 0:
				ans += i + 1
		yield ans
t = int(input())
ans = gift()
print(*ans, sep='\n')


for _ in range(int(input())):
	ss = input()
	l = []
	i = 0
	s = 0
	for e in ss:
		if e == '+':
			s += 1
		else:
			s -= 1
		l.append(s)
	k = min(l)
	if k >= 0:
		print(len(ss))
	else:
		p = abs(k)
		d = p
		c = 0
		ans = 0
		ans += len(ss)
		ddd = []
		prev = l[0]
		cc = 0
		for i in range(len(l)):
			if l[i] < 0 and abs(l[i]) > abs(cc):
				if l[i] == k:
					ddd.append((abs(p + cc), i + 1))
					break
				c = abs(l[i])
				ddd.append((abs(c + cc), i + 1))
				cc = min(l[i], prev)
				prev = l[i]
				if cc == p:
					break
		for (e, f) in ddd:
			ans += e * f
		print(ans)


t = int(input())
for _ in range(t):
	s = input()
	res = 0
	add = 0
	cur_len = 0
	for i in range(len(s)):
		cur_len += 1
		if s[i] == '+':
			add += 1
		if s[i] == '-':
			add -= 1
		if i == len(s) - 1 and add >= 0:
			res += cur_len
		if add < 0:
			res += cur_len
			if i == len(s) - 1:
				res += cur_len
			add = 0
	print(res)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
for _ in range(int(input())):
	s = list(input())
	a = 0
	z = []
	t = -1
	for i in range(len(s)):
		if s[i] == '+':
			a += 1
		else:
			a -= 1
		if a == t:
			z.append(i + 1)
			t -= 1
	if len(z) == 0:
		print(len(s))
	else:
		print(sum(z) + len(s))


for t in range(int(input())):
	s = input()
	n = len(s)
	arr = [0] * n
	tmp = 0
	for i in range(n):
		if s[i] == '+':
			tmp += 1
		else:
			tmp -= 1
		xz = -1 - tmp
		if xz >= 0 and arr[xz] == 0:
			arr[xz] = i + 1
	print(sum(arr) + n)


import os
from math import *
t = int(input())
while t:
	t -= 1
	s1 = input()
	(k, s) = [0] * 2
	count = 1
	ans = 0
	for x in s1:
		if x == '-':
			if s + k - 1 < 0:
				k += 1
				ans += count
			s -= 1
		else:
			if s + k + 1 < 0:
				ans += count
				k += 1
			s += 1
		count += 1
	print(ans + len(s1))


def solve():
	s = input()
	cnt = 0
	maxcnt = 0
	for i in s:
		if i == '-':
			cnt += 1
		else:
			cnt -= 1
		maxcnt = max(maxcnt, cnt)
	M = maxcnt
	cnt = 0
	maxcnt = 0
	ans = 0
	for i in s:
		ans += M - maxcnt + 1
		if i == '-':
			cnt += 1
		else:
			cnt -= 1
		maxcnt = max(maxcnt, cnt)
	print(ans)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		elif input_format == 6:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enum = enumerate

def func(s):
	res = 0
	for init in range(0, 10 ** 10):
		cur = init
		ok = True
		for i in range(0, len(s)):
			res += 1
			if s[i] == '+':
				cur += 1
			else:
				cur -= 1
			if cur < 0:
				ok = False
				break
		if ok:
			break
	return res

def solve():
	s = input(3)
	m = 10 ** 9
	c = 0
	t = len(s)
	for i in range(0, len(s)):
		if s[i] == '-':
			c -= 1
		else:
			c += 1
		if c < m:
			log('>>>', i)
			m = c
			if m < 0:
				t += i + 1
	if m >= 0:
		t = len(s)
	out(t)
	return
for i in range(input(11)):
	solve()


import sys
t = int(sys.stdin.readline())
while t:
	s = sys.stdin.readline().strip()
	d = {}
	curr = 0
	minn = float('inf')
	n = len(s)
	for i in range(n):
		if s[i] == '-':
			curr -= 1
		else:
			curr += 1
		if curr not in d:
			d[curr] = i + 1
		minn = min(minn, curr)
	res = 0
	for i in range(abs(minn)):
		if -(i + 1) in d:
			res += d[-(i + 1)]
		else:
			break
	res += n
	print(res)
	t -= 1


from collections import Counter
cases = int(input())
for t in range(cases):
	s = input()
	check = 0
	counter = 1
	res = 0
	for i in s:
		if i == '-':
			check -= 1
		else:
			check += 1
		if check == -1:
			res += counter
			check = 0
		counter += 1
	res += counter - 1
	print(res)


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	s = input()
	pc = 0
	mc = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '-' and pc <= 0:
			ans += i + 1
		elif s[i] == '-' and pc > 0:
			pc -= 1
		else:
			pc += 1
	print(ans + len(s))


def f(l):
	n = len(l)
	sl = [0] * n
	sl[0] = 1 if l[0] == '+' else -1
	for i in range(1, n):
		sl[i] = sl[i - 1] + (1 if l[i] == '+' else -1)
	nl = []
	ref = 0
	for i in range(n):
		if sl[i] < ref:
			nl.append(i + 1)
			ref -= 1
	return sum(nl) + n
n = int(input())
for _ in range(n):
	print(f(input()))


test = int(input())
for _ in range(test):
	s = input()
	curr = 0
	res = 0
	length = len(s)
	for i in range(length):
		if s[i] == '-':
			curr -= 1
		else:
			curr += 1
		if curr < 0:
			res += i + 1
			curr = 0
	print(res + length)


import math
for _ in range(int(input())):
	s = input()
	score = 0
	a = 0
	S = []
	for i in s:
		if i == '+':
			score += 1
		else:
			score -= 1
		S.append(score)
		if score < 0:
			a = -1
	if a != -1:
		print(len(s))
		continue
	cur = 0
	ans = 0
	for i in range(len(S)):
		if S[i] + cur < 0:
			ans += i + 1
			cur += 1
	ans += len(s)
	print(ans)


from sys import stdin
t = int(stdin.readline().strip())
for i in range(t):
	s = stdin.readline().strip()
	cur = 0
	ans = len(s)
	minimum = 0
	for (i, c) in enumerate(s):
		if c == '+':
			cur += 1
		else:
			cur -= 1
			if cur < minimum:
				ans += i + 1
				minimum = cur
	print(ans)


T = int(input())
from collections import Counter
for _ in range(T):
	s = input()
	n = len(s)
	cur = 0
	al = 0
	ans = 0
	now = []
	for i in range(n):
		if s[i] == '+':
			al += 1
		else:
			al -= 1
		if cur > al:
			now.append(i + 1)
			ans += i + 1
			cur = al
	print(ans + n)


t = int(input())
for T in range(t):
	s = input()
	n = len(s)
	l = []
	for i in s:
		if i == '-':
			l.append(-1)
		else:
			l.append(1)
	(ans, cur) = (0, 0)
	for i in range(n):
		if s[i] == '-':
			if cur == 0:
				ans += i + 1
				continue
		cur += l[i]
	ans += n
	print(ans)


for _ in range(int(input())):
	s = []
	for (i, x) in enumerate(input()):
		if x == '+':
			s.append(1)
		else:
			s.append(-1)
	SUM = ans = 0
	for (i, x) in enumerate(s):
		SUM += x
		if SUM == -1:
			SUM = 0
			ans += i + 1
	ans += i + 1
	print(ans)


from random import randint
from collections import defaultdict
it = lambda : list(map(int, input().strip().split()))
INF = float('inf')

def solve():
	S = input().strip()
	N = len(S)
	mni = 0
	ans = 0
	cur = 0
	for i in range(N):
		if S[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < mni:
			mni = cur
			ans += i + 1
	ans += N
	return ans
T = int(input())
for _ in range(T):
	print(solve())


import math
wqr = int(input())
for er in range(wqr):
	a = list(input())
	temp = []
	for i in range(len(a)):
		if i == 0:
			if a[i] == '+':
				temp.append(1)
			else:
				temp.append(-1)
			continue
		if a[i] == '+':
			temp.append(temp[i - 1] + 1)
		else:
			temp.append(temp[i - 1] - 1)
	i = 0
	ans = 0
	for j in range(len(a) + 1):
		if j + temp[i] < 0:
			ans += i + 1
		else:
			while i < len(a):
				if j + temp[i] < 0:
					break
				else:
					i += 1
			if i < len(a):
				ans += i + 1
			else:
				ans += i
		if i >= len(a):
			break
	print(ans)


def solve(s):
	tol = 0
	plus = 0
	minus = 0
	res = 0
	for i in range(1, len(s) + 1):
		if s[i - 1] == '+':
			plus += 1
		else:
			minus += 1
			if tol + plus < minus:
				res += i
				tol += 1
	res += len(s)
	print(res)

def main():
	for _ in range(int(input())):
		solve(input())
main()


def read_list():
	return list(map(int, input().strip().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
N = int(input())
for _ in range(N):
	s = input()
	res = 0
	length = len(s)
	cur = 0
	i = 0
	while i < length:
		if s[i] == '-':
			cur -= 1
		else:
			cur += 1
		i += 1
		if cur < 0:
			res += i
			cur = 0
	print(res + length)


import sys
from bisect import bisect_left, bisect_right
INF = 1 << 60
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	cur = 0
	x = [0 for i in range(n)]
	for i in range(n):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		x[i] = cur
	upper = 0
	ans = len(s)
	for i in range(n):
		if x[i] < upper:
			ans += i + 1 + upper - x[i] - 1
			upper -= 1
	print(ans)


for _ in range(int(input())):
	s = input()
	y = 0
	v = []
	for i in range(len(s)):
		if s[i] == '+':
			y += 1
		else:
			y -= 1
		if y < 0:
			v.append([y, i + 1])
	v.sort()
	if len(v) == 0:
		print(len(s))
		continue
	v = sorted(v, key=lambda x: x[1])
	res = 0
	u = 0
	for i in range(len(v)):
		if abs(v[i][0]) > u:
			res += (abs(v[i][0]) - u) * v[i][1]
			u = abs(v[i][0])
	res += len(s)
	print(res)


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
for _ in range(int(input())):
	s = input()
	n = len(s)
	ans = n
	cur = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			ans += i + 1
			cur += 1
	print(ans)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().strip()
	s = list(s)
	n = len(s)
	d = dd(int)
	cs = 0
	mi = 1000000000000000
	for i in range(0, n):
		if s[i] == '-':
			cs -= 1
		else:
			cs += 1
		mi = min(cs, mi)
		if cs not in d:
			d[cs] = i + 1
	ans = n
	for i in range(0, abs(mi)):
		b = -abs(i) - 1
		ans += d[b]
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	count = len(s)
	now = 0
	m = 0
	for i in range(len(s)):
		if s[i] == '-':
			now += 1
		else:
			now -= 1
		if m < now:
			count += i + 1
			m = now
	print(count)


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		s = input()
		res = len(s)
		i = 1
		plus_count = 0
		minus_count = 0
		for i in range(1, len(s) + 1):
			c = s[i - 1]
			if c == '+':
				plus_count += 1
			else:
				minus_count += 1
			if plus_count >= minus_count:
				pass
			else:
				res += i
				plus_count += 1
		print(res)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	a = input()
	s = 0
	b = [0]
	for i in range(len(a)):
		if a[i] == '+':
			s += 1
		else:
			s -= 1
		b.append(s)
	d = 0
	mi = 0
	for i in range(len(b)):
		if b[i] < mi:
			d += i
			mi = min(b[i], mi)
	print(d + len(a))


test = int(input())
for i in range(test):
	s = input()
	dp = [0] * len(s)
	balance = -1 if s[0] == '-' else 1
	max_ = 0
	dp[0] = 1 if s[0] == '-' else 0
	for i in range(1, len(s)):
		balance += 1 if s[i] == '+' else -1
		if balance < 0:
			if dp[i - 1] + balance < 0:
				dp[i] = -balance
			else:
				dp[i] = dp[i - 1]
		else:
			dp[i] = dp[i - 1]
	ans = 0
	from collections import defaultdict
	cnt = defaultdict(lambda : -1)
	for i in range(len(dp)):
		cnt[dp[i]] = i
	ans = 0
	for i in range(max(dp) + 1):
		ans += min(cnt[i] + 2, len(s))
	print(ans)


import sys
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right
from collections import deque
from collections import Counter
from itertools import accumulate, combinations, permutations
from heapq import heapify, heappop, heappush
from functools import lru_cache

def input():
	return sys.stdin.readline()[:-1]

def printl(li):
	_ = print(*li, sep='\n') if li else None

def argsort(s, return_sorted=False):
	inds = sorted(range(len(s)), key=lambda k: s[k])
	if return_sorted:
		return (inds, [s[i] for i in inds])
	return inds

def alp2num(c, cap=False):
	return ord(c) - 97 if not cap else ord(c) - 65

def num2alp(i, cap=False):
	return chr(i + 97) if not cap else chr(i + 65)

def matmat(A, B):
	(K, N, M) = (len(B), len(A), len(B[0]))
	return [[sum([A[i][k] * B[k][j] for k in range(K)]) for j in range(M)] for i in range(N)]

def matvec(M, v):
	(N, size) = (len(v), len(M))
	return [sum([M[i][j] * v[j] for j in range(N)]) for i in range(size)]

def T(M):
	(n, m) = (len(M), len(M[0]))
	return [[M[j][i] for j in range(n)] for i in range(m)]

def main():
	mod = 1000000007
	s = input()
	acc = []
	cur = 0
	for si in s:
		if si == '-':
			cur -= 1
		else:
			cur += 1
		acc.append(cur)
	cur = 0
	tot = len(s)
	for (i, a) in enumerate(acc):
		if a < cur:
			cur = a
			tot += i + 1
	print(tot)
q = int(input())
for _ in range(q):
	main()


t = int(input())
for tit in range(t):
	s = input()
	cur = 0
	res = 0
	sum = 0
	for (i, ele) in enumerate(s):
		if ele == '-':
			sum -= 1
		elif ele == '+':
			sum += 1
		if cur + sum == -1:
			res += i + 1
			cur += 1
	print(res + len(s))


t = int(input())
for ii in range(t):
	s = input()
	worst = 0
	curr = 0
	count = 0
	ptr = 0
	peak = -1
	itr = 0
	for i in s:
		ptr += 1
		if i == '+':
			curr += 1
		else:
			curr -= 1
		if curr < worst:
			worst = curr
			peak = ptr
		if ptr == len(s) or curr + itr < 0:
			count += ptr
			itr += 1
	if peak == len(s):
		count += len(s)
	print(count)


zero_condn = True
n = int(input())
for xxx in range(n):
	strfg = input()
	cfcfcfcfc = dict()
	bhbhbjj = 0
	hbkbbkk = 1000000000
	for i in range(len(strfg)):
		if strfg[i] == '-' and zero_condn:
			bhbhbjj = bhbhbjj - 1
		if strfg[i] == '+':
			bhbhbjj = bhbhbjj + 1
		hbkbbkk = min(hbkbbkk, bhbhbjj)
		if bhbhbjj not in cfcfcfcfc.keys():
			cfcfcfcfc[bhbhbjj] = i
	hbhbj = 0
	if hbkbbkk >= 0:
		print(len(strfg))
		continue
	hbhbj = hbhbj + len(strfg)
	for i in range(0, -1 * hbkbbkk):
		hbhbj = hbhbj + cfcfcfcfc[-1 * i - 1] + 1
	print(hbhbj)


for _ in range(int(input())):
	s = [x for x in input()]
	res = len(s)
	c = 0
	j = 0
	l = []
	prev = 0
	for i in range(len(s)):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
		if c < prev:
			prev = c
			l.append([c, i])
	prev = 0
	for i in range(len(l)):
		res += abs((abs(l[i][0]) - prev) * (l[i][1] + 1))
		prev = abs(l[i][0])
	print(res)


T = int(input())
for test in range(T):
	s = input()
	cuml = [0] * (len(s) + 1)
	ans = len(s)
	minnum = -1
	for i in range(1, len(s) + 1):
		if s[i - 1] == '+':
			cuml[i] = cuml[i - 1] + 1
		else:
			cuml[i] = cuml[i - 1] - 1
			if cuml[i] == minnum:
				ans += i
				minnum -= 1
	print(ans)


for _ in range(int(input())):
	s = input()
	res = 0
	val = 0
	init = 0
	for (x, i) in zip(s, range(1, len(s) + 1)):
		if x == '+':
			val += 1
		elif x == '-':
			val -= 1
		if val < 0:
			res += i
			val = 0
	res += len(s)
	print(res)


from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
	t = I()
	for _ in range(t):
		s = input()
		n = len(s)
		f = [0] * n
		k = 0
		ans = 0
		for i in range(n):
			if k == -1:
				f[i] += 1
			if s[i] == '-':
				k = max(k - 1, -1)
			else:
				k = max(k + 1, 1)
		f = list(accumulate(f))
		if k < 0:
			ans += n
		m = max(f) + 1
		for i in f:
			ans += m - i
		print(ans)
	return
solve()


for i in range(int(input())):
	s = input()
	(cur, min, ans) = (0, 0, len(s))
	for j in range(len(s)):
		if s[j] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < min:
			min = cur
			ans += j + 1
	print(ans)


import math
t = int(input())
for w in range(t):
	s = input()
	n = len(s)
	m = 1000001
	c = 0
	d = {}
	for i in range(n):
		if s[i] == '-':
			c -= 1
			m = min(m, c)
			if m < 0:
				if m in d:
					d[m] = min(d[m], i)
				else:
					d[m] = i
		else:
			c += 1
	if m >= 0:
		print(n)
	else:
		res = 0
		for i in range(-1, m - 1, -1):
			res += d[i] + 1
		print(res + n)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	S = input()
	N = len(S)
	D = {}
	cur = 0
	for (i, s) in enumerate(S):
		if s == '+':
			cur += 1
		else:
			cur -= 1
			if cur < 0 and cur not in D:
				D[cur] = i + 1
	ans = sum(D.values()) + N
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	S = input().strip()
	K = 0
	MIN = 0
	ANS = len(S)
	for i in range(len(S)):
		if S[i] == '+':
			K += 1
		else:
			K -= 1
		if K < MIN:
			ANS += i + 1
			MIN = K
	print(ANS)


for _ in range(int(input())):
	s = input()
	sum = 0
	res = 0
	cnt = 0
	arr = []
	for i in range(len(s)):
		if s[i] == '+':
			arr.append(1)
		else:
			arr.append(-1)
	for i in arr:
		res += i
		if res == -1:
			cnt += 1
			sum += cnt
			res += 1
		else:
			cnt += 1
	sum += cnt
	print(sum)


def solve():
	s = input()
	ans = 0
	cur = 0
	for i in range(0, len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			cur = 0
			ans += i + 1
	if ans > 0:
		return ans + len(s)
	return len(s)

def main():
	t = int(input())
	while t:
		print(solve())
		t -= 1
main()


for _ in range(int(input())):
	s = input()
	n = len(s)
	pref = [0] * (n + 1)
	pos = {}
	for i in range(1, n + 1):
		pref[i] = pref[i - 1]
		if s[i - 1] == '+':
			pref[i] += 1
		else:
			pref[i] -= 1
		if pref[i] < 0:
			t = -pref[i]
			if not t in pos:
				pos[t] = i
	res = 0
	for i in range(1, 100000000):
		if not i in pos:
			res += n
			break
		else:
			res += pos[i]
	print(res)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input()
	n = len(s) - 1
	ru = [0] * (n + 1)
	for i in range(n):
		if s[i] == '+':
			ru[i + 1] = ru[i] + 1
		else:
			ru[i + 1] = ru[i] - 1
	init = -1
	ans = 0
	for (i, val) in enumerate(ru):
		if val == init:
			ans += i
			init -= 1
	print(ans + n)


for _ in range(int(input())):
	s = input()
	minus = []
	cur = 0
	n = len(s)
	for i in range(n):
		if s[i] == '-' and cur == 0:
			minus += [i]
		elif s[i] == '-' and cur != 0:
			cur -= 1
		else:
			cur += 1
	ans = 0
	for i in range(len(minus)):
		ans += minus[i] + 1
	print(ans + len(s))


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		s = insr()
		curr = 0
		arr = [0]
		for i in s:
			if i == '+':
				arr.append(arr[-1] + 1)
			else:
				arr.append(arr[-1] - 1)
		arr.pop(0)
		extra = 0
		last = 0
		for i in range(0, len(s)):
			if arr[i] < last:
				extra = extra + abs(arr[i] - last) * (i + 1)
				last = arr[i]
		extra = extra + len(s)
		print(extra)
main()


t = int(input())
for ___ in range(t):
	s = input()
	(a, length) = ([], len(s))
	(current_sum, current_max) = (0, 0)
	for i in range(length):
		ch = s[i]
		if ch == '-':
			current_sum -= 1
		else:
			current_sum += 1
		if -current_sum > current_max:
			current_max = -current_sum
		a.append(current_max)
	if current_max == 0:
		print(length)
	else:
		moves = current_max + 1
		cur = 0
		summ = 0
		for i in range(length):
			if a[i] <= cur:
				summ += moves
			else:
				cur += 1
				summ += moves
				moves -= 1
		print(summ)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	s = input().split()[0]
	n = len(s)
	pre = [0]
	d = dd(int)
	for i in range(n):
		if s[i] == '+':
			pre.append(pre[-1] + 1)
		else:
			pre.append(pre[-1] - 1)
		if d[pre[-1]] == 0:
			d[pre[-1]] = i + 1
	ans = 0
	i = 0
	while 1:
		cur = i + 1
		if d[-cur]:
			ans += d[-cur]
		else:
			ans += n
			break
		i += 1
	print(ans)
	t -= 1


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	for _ in range(ii()):
		s = si()
		n = len(s) - 1
		c = 0
		res = 0
		for i in range(n):
			if s[i] == '+':
				c += 1
			else:
				c -= 1
			if c < 0:
				c = 0
				res += i + 1
		print(res + n)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


for _ in range(int(input())):
	ar = list(input())
	kek = 0
	lol = 0
	for i in range(len(ar)):
		if ar[i] == '-':
			kek += 1
		else:
			kek -= 1
		if kek > lol:
			lol = kek
	fifi = [-1] * lol
	cur = 0
	for i in range(len(ar)):
		if ar[i] == '-':
			cur += 1
			if cur > 0 and fifi[cur - 1] == -1:
				fifi[cur - 1] = i + 1
		else:
			cur -= 1
	ans = 0
	for elem in fifi:
		ans += elem
	print(len(ar) + ans)


for _ in range(int(input())):
	arr = list(input().strip())
	sm = [0]
	for a in arr:
		if a == '+':
			sm.append(sm[-1] + 1)
		else:
			sm.append(sm[-1] - 1)
	sm.pop(0)
	bc = 0
	ans = 0
	i = 0
	n = len(sm)
	for i in range(n):
		cur = sm[i]
		if cur + bc < 0:
			jumps = abs(bc + cur)
			ans += (i + 1) * jumps
			bc += jumps
	ans += n
	print(ans)


for t in range(int(input())):
	s = input()
	minuses = 0
	pluses = 0
	adventure = 0
	ans = len(s)
	for c in range(len(s)):
		if s[c] == '-':
			minuses += 1
		else:
			pluses += 1
		if minuses > pluses + adventure:
			ans += c + 1
			adventure += 1
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	arr = [0] * len(s)
	if s[0] == '-':
		arr[0] = -1
	else:
		arr[0] = 1
	l = len(s)
	for i in range(1, l):
		if s[i] == '-':
			arr[i] = arr[i - 1] - 1
		else:
			arr[i] = arr[i - 1] + 1
	l = len(arr)
	i = 0
	k = 0
	res = 0
	while i < l:
		if arr[i] + k < 0:
			res = res + (i + 1)
			k += 1
			i -= 1
		i += 1
	res += i
	print(res)


for t in range(int(input())):
	s = input()
	l = len(s)
	c = 0
	i = 0
	ls = []
	if s[0] == '+':
		ls.append(1)
		c = 1
		i = 1
	while i < l:
		if s[i] == '-':
			c = c - 1
			ls.append(c)
		else:
			if s[i - 1] == '+':
				c = c + 1
			elif ls[i - 1] < 0:
				c = 1
			elif ls[i - 1] >= 0:
				c = c + 1
			ls.append(c)
		i = i + 1
	ans = 0
	for i in range(l):
		if s[i] == '-' and ls[i] < 0:
			ans = ans + i + 1
	print(ans + l)


n = int(input())
for _ in range(n):
	s = input()
	l = len(s)
	res = l
	t = 0
	for i in range(l):
		if s[i] == '-':
			if t <= 0:
				res += i + 1
			else:
				t -= 1
		else:
			t += 1
	print(res)


t = int(input())
l = []
for _ in range(t):
	l.append(input())
for s in l:
	p = 0
	m = 0
	ok = 0
	res = 0
	for i in range(len(s)):
		if s[i] == '+':
			p = p + 1
		else:
			m = m + 1
		if m > ok + p:
			res = res + (i + 1)
			ok = ok + 1
	res = res + len(s)
	print(res)


from sys import stdin
A = int(stdin.readline())
for u in range(0, A):
	B = stdin.readline()
	C = list()
	temp = 0
	for k in B:
		if k == '+':
			temp += 1
			C.append(temp)
		elif k == '-':
			temp -= 1
			C.append(temp)
	record = 0
	ans = 0
	for k in range(0, len(C)):
		if C[k] < record:
			record = C[k]
			ans += k + 1
	print(ans + len(B) - 1)


t = input()
for _ in range(int(t)):
	s = input()
	res = 0
	(plus, minus) = (0, 0)
	for i in range(len(s)):
		if s[i] == '+':
			res = res + 1
			plus += 1
		elif plus > 0:
			res = res + 1
			plus -= 1
		else:
			res = res + i + 2
	print(res)


t = int(input())
for i in range(0, t):
	s = input()
	c = 0
	d = 0
	zz = 0
	while c < len(s):
		if s[c] == '+':
			d = d + 1
		else:
			d = d - 1
		if d < 0:
			d = 0
			zz = zz + 1 + c
		c = c + 1
	print(zz + len(s))


o = int(input())
for _ in range(o):
	s = input()
	res = 0
	n = len(s)
	count = n
	for i in range(n):
		if s[i] == '+':
			res += 1
		elif s[i] == '-':
			res -= 1
		if res < 0:
			count += i + 1
			res = 0
	print(count)


t = int(input())
for i in range(t):
	s = list(input())
	re = 0
	x = 0
	for j in range(len(s)):
		re += 1
		if s[j] == '+':
			x += 1
		else:
			x -= 1
		if x < 0:
			re += j + 1
			x = 0
	print(re)


import sys

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	s = input()
	curr = 0
	i = 0
	n = len(s)
	brpts = []
	while i < n:
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < 0:
			brpts.append(i)
			curr = 0
		i += 1
	brpts.append(n - 1)
	ans = 0
	for i in range(len(brpts)):
		ans += brpts[i] + 1
	print(ans)


from sys import stdin

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	s = inp()
	akbarTyz = 10 ** 9
	tyz = 0
	ans = len(s)
	counter = 1
	for i in range(len(s)):
		if s[i] == '+':
			tyz += 1
		else:
			tyz -= 1
		if tyz < akbarTyz and tyz < 0:
			ans += counter
		akbarTyz = min(akbarTyz, tyz)
		counter += 1
	print(ans)


for _ in range(int(input())):
	a = input()
	(r, q) = (0, 0)
	w = len(a)
	for i in range(w):
		if a[i] == '-':
			r += 1
		else:
			q += 1
		if r > q:
			w += i + 1
			r -= 1
	print(w)


t = int(input())
cases = []
for i in range(t):
	string = input()
	cases.append(string)
for case in cases:
	res = 0
	index_res_update = 0
	for (i, char) in enumerate(case):
		if char == '+':
			index_res_update += 2
		elif i == index_res_update:
			res += i + 1
			index_res_update += 1
	if index_res_update >= len(case):
		res += len(case)
	print(res)


from sys import stdout, stdin
d = dict()
d['+'] = 1
d['-'] = -1
for _ in range(int(stdin.readline())):
	s = stdin.readline()
	n = len(s) - 1
	ls = [d[s[0]]]
	for i in range(1, n):
		ls.append(ls[i - 1] + d[s[i]])
	cnt = 0
	conv = 0
	for i in range(n):
		if ls[i] + conv < 0:
			cnt += (i + 1) * abs(ls[i] + conv)
			conv += abs(ls[i] + conv)
	stdout.write(f'{cnt + n}\n')


T = int(input())
for _ in range(T):
	S = input()
	a = v = mn = 0
	for (i, c) in enumerate(S):
		if c == '+':
			v += 1
		else:
			v -= 1
		if v < mn:
			mn = v
			a += i + 1
	print(a + len(S))


t = int(input())
for i in range(t):
	s = input()
	min_v = 0
	value = 0
	max_index = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '+':
			value += 1
		else:
			value -= 1
		if value < min_v:
			min_v = value
			ans += i + 1
	print(ans + len(s))


def solve():
	s = input()
	(x, k) = (0, 0)
	for i in s:
		if i == '-':
			k += 1
		else:
			k -= 1
		x = max(x, k)
	res = len(s)
	if x > 0:
		ctr = 1
		c = 0
		l = 0
		for j in range(len(s)):
			l += 1
			if s[j] == '+':
				c += 1
			else:
				c -= 1
			if c < 0:
				res += l * (x - ctr + 1)
				c = 0
				ctr += 1
				l = 0
	print(res)
t = int(input())
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().strip('\n').split()))
res = []
for _ in range(int(input())):
	inp = input().strip('\n')
	(cur, mn, ans) = (0, 0, len(inp))
	for i in range(len(inp)):
		cur += 1 if inp[i] == '+' else -1
		if cur < mn:
			mn = cur
			ans += i + 1
	res.append(ans)
print('\n'.join(map(str, res)))


t = int(input())
for _ in range(t):
	s = list(input())
	res = 0
	curr = 0
	min_val = 0
	ind = 0
	while ind < len(s):
		i = s[ind]
		if i == '-':
			curr -= 1
			res += 1
			if curr < min_val:
				min_val = curr
				res += ind + 1
		else:
			curr += 1
			res += 1
		ind += 1
	print(res)


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	s = input()
	cur = 0
	res = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		res += 1
		if cur < 0:
			res += i + 1
			cur += 1
	print(res)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, pi, atan
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
for _ in range(int(inp())):
	s = inp()
	c = 0
	mn = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '-':
			c -= 1
		else:
			c += 1
		if c < mn:
			mn = c
			ans += i + 1
	print(ans + len(s))


t = int(input())
for _ in range(t):
	a = input()
	s = list(a)
	res = 0
	cur = 0
	track_minus = {}
	length = len(s)
	for i in range(length):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			if cur not in track_minus:
				track_minus[cur] = i + 1
	for loopthrough in track_minus.values():
		res += loopthrough
	res += length
	print(res)


for _ in range(int(input())):
	s = input()
	(p, m) = (s.count('+'), s.count('-'))
	val = m - p
	cur = 0
	check = 1
	sol = 0
	for (ind, x) in enumerate(s):
		cur += 1 if x == '-' else -1
		if cur == check:
			check += 1
			sol += ind + 1
	print(sol + len(s))


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	S = input()
	n = len(S)
	A = [0] * (n + 1)
	for i in range(n):
		if S[i] == '+':
			A[i + 1] = A[i] + 1
		else:
			A[i + 1] = A[i] - 1
	B = [0] * (n + 1)
	for i in range(1, n):
		B[i + 1] = min(B[i], A[i])
	ct = -min(A) + 1
	ans = 0
	for i in range(n):
		ans += ct + B[i + 1]
	print(ans)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
for _ in range(int(input())):
	s = input()
	n = len(s)
	a = 0
	ans = 0
	for i in range(n):
		if s[i] == '-':
			a -= 1
		else:
			a += 1
		if a < 0:
			ans += i + 1
			a = 0
	print(ans if a < 0 else ans + n)


t = int(input())
for test in range(t):
	s = input()
	res = 0
	cur = 0
	for i in range(len(s)):
		res += 1
		if s[i] == '-':
			cur -= 1
			if cur < 0:
				res += i + 1
				cur = 0
		elif s[i] == '+':
			cur += 1
	if cur < 0:
		res += len(s)
	print(res)


def solve():
	s = input()
	res = len(s)
	mn = 0
	ct = 0
	for n in range(len(s)):
		if s[n] == '+':
			ct += 1
		else:
			ct -= 1
		if ct < mn:
			mn = ct
			res += n + 1
	print(res)
for _ in range(int(input())):
	solve()


t = int(input())
for test in range(t):
	s = list(input())
	cum = []
	cur = 0
	m = 0
	res = 0
	ite = 0
	for (n, i) in enumerate(s):
		if i == '+':
			cur += 1
		else:
			cur -= 1
		if cur < m:
			res += (m - cur) * (n + 1)
			m = cur
		cum.append(m)
	print(res + len(s))


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def ref(S):
	s = S
	res = 0
	for init in range(100000000):
		cur = init
		ok = True
		for i in range(len(s)):
			res = res + 1
			if s[i] == '+':
				cur = cur + 1
			else:
				cur = cur - 1
			if cur < 0:
				ok = False
				break
		if ok:
			break
	return res

def slv(S):
	p = 0
	ans = 0
	cur = -1
	L = len(S)
	S = [c for c in S]
	S.reverse()
	for i in range(len(S)):
		cur += 1
		while S:
			if S.pop() == '+':
				cur += 1
			else:
				cur -= 1
			if cur < 0:
				break
		ans += L - len(S)
		if len(S) == 0:
			break
	if cur < 0:
		ans += L
	return ans

def main():
	for _ in range(read_int()):
		S = read_str()
		print(slv(S))
main()


for _ in range(int(input())):
	napis = input()
	(cur, mn, res) = (0, 0, len(napis))
	for i in range(len(napis)):
		if napis[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < mn:
			mn = cur
			res += i + 1
	print(res)


import math
import sys
from itertools import permutations
input = sys.stdin.readline
t = int(input())
for i in range(t):
	s = list(input())
	if s[-1] == '\n':
		s.pop()
	arr = []
	cur = 0
	for j in range(len(s)):
		if s[j] == '-':
			cur += 1
			arr.append(cur)
		else:
			cur -= 1
			arr.append(cur)
	maxx = 0
	ans = 0
	for j in range(len(arr)):
		if arr[j] > maxx:
			ans += j + 1
			maxx = arr[j]
	ans += len(arr)
	print(ans)


for cases in range(int(input())):
	s = input()
	curr = 0
	ans = 0
	for i in range(0, len(s)):
		if s[i] == '-':
			if curr == 0:
				ans += i + 1
			else:
				curr = curr - 1
		else:
			curr += 1
	ans += len(s)
	print(ans)


t = int(input())

def get_cumm(s):
	cur = 0
	ans = []
	for ss in s:
		if ss == '-':
			cur -= 1
		else:
			cur += 1
		ans.append(cur)
	return ans
for i in range(t):
	s = input()
	cum = get_cumm(s)
	min_stack = []
	for (j, c) in enumerate(cum):
		if len(min_stack) == 0:
			if c < 0:
				min_stack.append([j, c])
		elif c < min_stack[-1][1]:
			min_stack.append([j, c])
	ans = 0
	cur = 0
	for v in min_stack:
		ans += (v[0] + 1) * (abs(v[1]) - cur)
		cur = abs(v[1])
	print(ans + len(s))


d = {'+': 1, '-': -1}
for _ in range(int(input())):
	s = input()
	l = len(s)
	dp = [0 for i in range(l)]
	k = 0
	for i in range(l):
		si = 0
		while k < l:
			si += d[s[k]]
			if si < 0:
				break
			k += 1
		if k == l:
			break
		dp[k] = i + 1
		k += 1
	ans = 0
	for i in range(l):
		if dp[i]:
			ans += i + 1
	print(ans + l)


t = int(input())
for tc in range(t):
	s = input()
	(cur, worst, ans) = (0, 0, 0)
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		if s[i] == '-':
			cur -= 1
		if cur < worst:
			ans += i + 1
			worst = cur
	ans += len(s)
	print(ans)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]

def makeit(s):
	l1 = [[s[0], 1]]
	for i in s[1:]:
		if i == l1[-1][0]:
			l1[-1][1] += 1
		else:
			l1.append([i, 1])
	return l1[:]
for _ in range(val()):
	s = st()
	curr = ans = 0
	ans2 = 0
	for i in range(len(s)):
		ans += 1
		ans2 += 1
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < 0:
			ans += ans2
			curr = 0
	print(ans)


case = int(input())
for _ in range(case):
	s = input()
	p = len(s)
	mini = 0
	tmp = 0
	for i in s:
		if i == '+':
			tmp += 1
		else:
			tmp -= 1
		if tmp < mini:
			mini = tmp
	if mini == 0:
		print(p)
		continue
	ok = -mini
	lst = [None] * ok
	cur = 0
	for i in range(p):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			tmp = cur + 1
			tmp = -tmp
			if lst[tmp] == None:
				lst[tmp] = i + 1
	print(sum(lst) + p)


def solve():
	s = input()
	cur = 0
	res = 0
	for (i, c) in enumerate(s):
		res += 1
		if c == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			res += i + 1
			cur = 0
	print(res)
t = int(input())
for _ in range(t):
	solve()


t = input()
t = int(t)

def solve(s):
	prefix_sum = [0 for i in range(len(s))]
	if s[0] == '-':
		prefix_sum[0] = -1
	else:
		prefix_sum[0] = 1
	for i in range(1, len(s)):
		if s[i] == '-':
			prefix_sum[i] = prefix_sum[i - 1] - 1
		else:
			prefix_sum[i] = prefix_sum[i - 1] + 1
	res = 0
	cur = 0
	cpk = 0
	while cpk < len(s):
		res += 1
		flag = prefix_sum[cpk]
		if flag < 0:
			flag = abs(flag)
		else:
			flag = 0
		while cpk < len(s) and cur >= flag:
			cpk += 1
			if cpk >= len(s):
				break
			flag = prefix_sum[cpk]
			if flag < 0:
				flag = abs(flag)
			else:
				flag = 0
		res += cpk
		cur += 1
	res -= 1
	print(res)
for i in range(t):
	s = input()
	solve(s)


kk = int(input())
while kk:
	li = list(input())
	q = w = 0
	kk -= 1
	for i in range(len(li)):
		if li[i] == '+':
			q += 1
		else:
			q -= 1
		if q < 0:
			w += i + 1
			q += 1
	print(w + len(li))


for _ in range(int(input())):
	S = input()
	a = []
	s = 0
	for i in S:
		if i == '+':
			s += 1
		else:
			s -= 1
		a.append(s)
	ans = 0
	cnt = 0
	temp = 0
	for i in range(len(a)):
		if a[i] < cnt:
			ans += i + 1
			cnt -= 1
			temp = i + 1
	if temp != len(a) and a[temp - 1] <= a[-1]:
		print(ans + len(a))
	elif ans == 0:
		print(len(a))
	elif temp == len(a):
		print(ans + len(a))
	else:
		print(ans)


t = int(input())
for _ in range(t):
	L = list(input())
	res = 0
	count = 0
	for n in range(len(L)):
		if L[n] == '-':
			if count == 0:
				res += n + 2
			else:
				res += 1
				count -= 1
		else:
			res += 1
			count += 1
	print(res)


t = int(input())
for _ in range(t):
	s = input()
	curr = 0
	mn = 0
	l = []
	for i in range(len(s)):
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < mn:
			mn = curr
			l.append([mn, i + 1])
	if len(l) > 0:
		ans = abs(l[0][0]) * l[0][1]
		for i in range(len(l) - 1):
			ans += abs(l[i + 1][0] - l[i][0]) * l[i + 1][1]
		print(len(s) + ans)
	else:
		print(len(s))


x = int(input())
for _ in range(x):
	string = input()
	res = 0
	n = len(string)
	count = n
	for i in range(n):
		if string[i] == '+':
			res += 1
		elif string[i] == '-':
			res -= 1
		if res < 0:
			count += i + 1
			res = 0
	print(count)


import sys
input = sys.stdin.buffer.readline
Q = int(input())
Ss = [list(input().rstrip()) for _ in range(Q)]
for S in Ss:
	L = len(S)
	D = {0: 1}
	t = 0
	for (i, s) in enumerate(S):
		if chr(s) == '+':
			t += 1
		else:
			t -= 1
		if t <= 0 and (not t in D):
			D[t] = i + 1
	ans = L - 1
	for (k, v) in D.items():
		ans += v
	print(ans)


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]

def solve():
	s = ii()
	count = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '-':
			if count == 0:
				ans += i + 2
			else:
				count -= 1
				ans += 1
		else:
			count += 1
			ans += 1
	print(ans)
	return
for t in range(int(ii())):
	solve()


import math

def solve():
	s = input()
	l = []
	cnt = 0
	for i in s:
		if i == '-':
			cnt -= 1
		else:
			cnt += 1
		l.append(cnt)
	cur = 0
	ans = 0
	n = len(s)
	for i in range(n):
		if cur + l[i] < 0:
			ans += i + 1
			cur += 1
	ans += n
	print(ans)
	return
t = 1
t = int(input())
while t > 0:
	t -= 1
	solve()


t = int(input())
for i in range(t):
	s = str(input())
	n = len(s)
	lis = []
	x = 0
	y = 0
	for j in range(n):
		if 0 == 0:
			if s[j] == '+':
				y += 1
			else:
				y -= 1
		if 0 == 0:
			if y + x < 0:
				z = 0 - (y + x)
				x += z
				lis.append(1 + z * (j + 1))
			else:
				lis.append(1)
	print(sum(lis))


for _ in range(int(input())):
	s = list(input())
	energy = 0
	ans = 0
	n = len(s)
	for i in range(0, n):
		if s[i] == '+':
			energy += 1
			ans += 1
		if s[i] == '-':
			energy -= 1
			if energy >= 0:
				ans += 1
			else:
				ans += 1
				ans += i + 1
				energy = 0
	print(ans)


t = int(input())
for z in range(t):
	s = input()
	running_total = []
	run = 0
	most_neg = 0
	for i in s:
		if i == '+':
			run += 1
		else:
			run -= 1
		running_total.append(run)
		if most_neg > run:
			most_neg = run
	pointer = 0
	res = 0
	alpha = 1 - most_neg
	for j in range(alpha):
		if pointer < len(s):
			while running_total[pointer] + j >= 0:
				pointer += 1
				if pointer == len(s):
					res -= 1
					break
			res += pointer + 1
	print(res)


import math
from itertools import accumulate

def main():
	t = Iint()
	for _ in range(t):
		s = [-1 if si == '-' else 1 for si in I()]
		a = list(accumulate(s))
		neg = -1
		ans = 0
		for (i, ai) in en(a):
			if ai == neg:
				ans += i + 1
				neg -= 1
		ans += len(s)
		print(ans)
FIO = True

def I():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))
if FIO:
	from io import BytesIO, IOBase
	import sys
	import os
en = enumerate
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


r = 0
i = -1
s = ''
a = []
b = 0
for z in range(int(input())):
	s = input()
	r = 0
	i = 0
	b = 0
	a = []
	for j in range(0, len(s)):
		if s[j] == '+':
			a.append(b + 1)
		else:
			a.append(b - 1)
		b = a[-1]
		if a[-1] + i < 0:
			r += len(a)
			i += 1
	print(r + len(s))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		s = S()
		r = len(s)
		c = 0
		mc = 0
		for i in range(len(s)):
			u = s[i]
			if u == '-':
				c -= 1
			else:
				c += 1
			if mc > c:
				mc = c
				r += i + 1
		rr.append(r)
	return JA(rr, '\n')
print(main())


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	a = input().strip()
	n = len(a)
	b = []
	cur = 0
	ans = n + 1
	res = 0
	for i in range(n):
		res += 1
		if a[i] == '-':
			cur -= 1
		else:
			cur += 1
		if cur < 0:
			res = res + (i + 1)
			cur += 1
	print(res)
for _ in range(I()):
	solve()


line = input()
t = int(line)
for _ in range(t):
	s = input()
	(res, cur, mx) = (0, 0, 0)
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < mx:
			mx = cur
			res += i + 1
	print(res + len(s))


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
for case in range(itg()):
	s = inp()
	ans = count = 0
	for i in range(len(s)):
		if s[i] == '+':
			count += 1
		else:
			count -= 1
		if count == -1:
			count = 0
			ans += i + 1
	ans += len(s)
	print(ans)


for _ in range(int(input())):
	s = input()
	ans = len(s)
	t = tt = 0
	for (i, j) in enumerate(s):
		t += 1 if j == '+' else -1
		if tt + t < 0:
			tt += 1
			ans += i + 1
	print(ans)


t = int(input())
arr = [[] for i in range(10 ** 6 + 10)]
for _ in range(t):
	s = input()
	summer = 0
	for (i, se) in enumerate(s):
		if se == '-':
			summer -= 1
		else:
			summer += 1
		if summer < 0:
			arr[abs(summer)].append(i)
	mainsum = 0
	i = 1
	while len(arr[i]) > 0:
		mainsum += arr[i][0] + 1
		arr[i] = []
		i += 1
	mainsum += len(s)
	print(mainsum)


def n_sum(ind):
	s = int(ind * (ind + 1) / 2)
	return s
t = int(input())
while t > 0:
	t -= 1
	s = input()
	ans = 0
	(cnt0, cnt1) = (0, 0)
	ok = False
	for i in range(len(s)):
		if s[i] == '-' and cnt1 == 0 and (not ok):
			cnt0 += 1
		elif s[i] == '+' and cnt1 == 0:
			ans += n_sum(cnt0 + 1)
			ok = True
			cnt1 += 1
			cnt0 = 0
		elif s[i] == '+':
			cnt1 += 1
			ans += 1
		elif s[i] == '-' and cnt1 > 0:
			ans += 1
			cnt1 -= 1
		elif ok and s[i] == '-' and (cnt1 == 0):
			ans += 1
			ans += i + 1
	if cnt0 > 0 and ans == 0:
		ans = cnt0 + n_sum(cnt0)
	print(ans)


for _ in range(int(input())):
	s = list(input())
	mi = 0
	count = 0
	ans = 0
	for i in range(0, len(s)):
		if s[i] == '+':
			count += 1
		else:
			count -= 1
		if count < mi:
			ans += i + 1
			mi = count
	print(ans + len(s))


for _ in range(int(input())):
	l = list(input())
	n = len(l)
	c = 0
	ans = 0
	pref = [0] * n
	for i in range(n):
		if l[i] == '-':
			pref[i] = -1
		else:
			pref[i] = 1
	for i in range(1, n):
		pref[i] = pref[i - 1] + pref[i]
	res = 0
	for i in range(n):
		if pref[i] + res >= 0:
			ans += 1
		else:
			ans += i + 1
			res += 1
			ans += 1
	print(ans)


for _ in range(int(input())):
	a = input()
	cnt = 0
	tot = 0
	for i in range(len(a)):
		if a[i] == '-':
			tot -= 1
		else:
			tot += 1
		if tot < 0:
			tot = 0
			cnt += i + 2
		else:
			cnt += 1
	print(cnt)


from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	cur = 0
	ans = 0
	for i in range(n):
		if s[i] == '-':
			cur -= 1
			if cur < 0:
				ans += i + 1
				cur = 0
		else:
			cur += 1
	ans += n
	print(ans)


t = int(input())
for case in range(t):
	string = input()
	height = 0
	last_neg = -1
	length = len(string)
	_sum = 0
	result = 0
	for index in range(length):
		char = string[index]
		if char == '+':
			_sum += 1
		else:
			_sum -= 1
		if _sum == last_neg:
			result += index + 1
			last_neg -= 1
	print(result + length)


for i in range(int(input())):
	s = input()
	n = len(s)
	curmin = []
	cur = 0
	for j in range(n):
		if s[j] == '-':
			cur -= 1
		else:
			cur += 1
		curmin.append(cur)
	curmin[0] = min(curmin[0], 0)
	for j in range(1, n):
		curmin[j] = min(curmin[j], curmin[j - 1])
	M = -min(curmin) + 1
	print(M * (n + 1) + sum(curmin) - 1)


for t in range(int(input())):
	s = input()
	if not s:
		print(0)
		continue
	arrp = [0] * len(s)
	arrm = [0] * len(s)
	if s[0] == '+':
		arrp[0] = 1
	else:
		arrm[0] = 1
	res = len(s)
	ch = set()
	if arrp[0] < arrm[0]:
		res += 1
		ch.add(arrm[0] - arrp[0])
	for i in range(1, len(s)):
		if s[i] == '+':
			arrp[i] = arrp[i - 1] + 1
			arrm[i] = arrm[i - 1]
		else:
			arrp[i] = arrp[i - 1]
			arrm[i] = arrm[i - 1] + 1
		if arrp[i] < arrm[i] and arrm[i] - arrp[i] not in ch:
			res += i + 1
			ch.add(arrm[i] - arrp[i])
	print(res)


import io
import os
from collections import Counter, defaultdict, deque

def solve(S):
	res = 0
	for init in range(0, 9999999):
		cur = init
		ok = True
		for i in range(0, len(S)):
			res = res + 1
			if S[i] == '+':
				cur = cur + 1
			else:
				cur = cur - 1
			if cur < 0:
				ok = False
				break
		if ok:
			break
	return res

def solve(S):
	pref = [0]
	cur = 0
	for i in range(0, len(S)):
		if S[i] == '+':
			cur = cur + 1
		else:
			cur = cur - 1
		pref.append(cur)
	first = {}
	for (i, p) in enumerate(pref):
		if p not in first:
			first[p] = i
	ans = 0
	for (k, v) in first.items():
		if k <= 0:
			ans += v
	return ans + len(S)
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	S = input().decode().rstrip()
	ans = solve(S)
	print(ans)


for _ in range(int(input())):
	s = input()
	res = 0
	cur = 0
	i = 0
	while i != len(s):
		if s[i] == '-':
			if cur < 1:
				cur += 1
				res += i + 1
				continue
			cur -= 1
		if s[i] == '+':
			cur += 1
		i += 1
	print(res + len(s))


import sys
import math
from collections import defaultdict

def solve(test):
	s = list(input())
	n = len(s)
	res = 0
	plus = 0
	for i in range(n):
		if s[i] == '-':
			if plus:
				plus -= 1
			else:
				res += i + 1
		else:
			plus += 1
	res += n
	print(res)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


def solve():
	s = input()
	ans = 0
	k = 0
	kp = 0
	t = s[-1] == '-'
	for i in range(len(s)):
		if s[i] == '-':
			kp -= 1
		else:
			kp += 1
		k = min(k, kp)
	k = -k + 1
	kp = 0
	lkp = 0
	for i in range(len(s)):
		if s[i] == '-':
			kp -= 1
		else:
			kp += 1
		ans += k
		if kp < min(0, lkp):
			k += kp - lkp
			lkp = kp
	print(ans)
for i in range(int(input())):
	solve()


from collections import defaultdict
Q = int(input())
for _ in range(Q):
	s = input()
	tmp = 0
	ans = 0
	dfd = defaultdict(lambda : 0)
	for (cnt, i) in enumerate(s):
		if i == '+':
			tmp += 1
		else:
			tmp -= 1
		if tmp < 0 and dfd[tmp] == 0:
			ans += cnt + 1
			dfd[tmp] = 1
	print(ans + len(s))


import math as mt
import sys, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
from collections import defaultdict
t = I()
for _ in range(t):
	s = input().strip()
	p = 0
	l = []
	for i in range(len(s)):
		if s[i] == '+':
			p += 1
			l.append(p)
		else:
			p -= 1
			l.append(p)
	d = defaultdict(int)
	for i in range(len(s)):
		if d[l[i]] == 0:
			d[l[i]] = i + 1
	c = 0
	ans = 0
	while True:
		if d[-(c + 1)] == 0:
			ans += len(s)
			break
		else:
			ans += d[-(c + 1)]
		c += 1
	print(ans)


import math
t = int(input())
while t:
	a = list()
	b = dict()
	s = input()
	cur = 0
	cur_min = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		cur_min = min(cur_min, cur)
		a.append(cur)
	for i in range(len(s) - 1, -1, -1):
		if a[i] < 0:
			b[-a[i]] = i + 1
	ans = len(s)
	if cur_min >= 0:
		print(ans)
	else:
		for i in range(-cur_min):
			ans += b[i + 1]
		print(ans)
	t -= 1


def solve():
	arr = list(input())
	cnt = 0
	cntValues = []
	for (idx, e) in enumerate(arr):
		if e == '+':
			cnt += 1
		else:
			cnt -= 1
		if cnt < 0:
			cntValues.append(1 + idx)
			cnt += 1
	ans = len(arr)
	if bool(cntValues):
		ans += sum(cntValues)
	return ans
for _ in range(int(input())):
	print(solve())


for _ in range(int(input())):
	s = input()
	count = 0
	llist = [0] * (len(s) + 1)
	for i in range(len(s)):
		if s[i] == '-':
			llist[i] = llist[i - 1] - 1
		else:
			llist[i] = llist[i - 1] + 1
	mina = 0
	tlist = []
	for i in range(len(llist)):
		t = llist[i]
		if mina > t:
			tlist.append([llist[i], i + 1])
			mina = t
	if len(tlist) == 0:
		print(len(s))
	else:
		res = tlist[0][1] + len(s)
		for i in range(1, len(tlist)):
			res += (tlist[i - 1][0] - tlist[i][0]) * tlist[i][1]
		print(res)


t = int(input())
while t > 0:
	s = list(input())
	c = 0
	a = 0
	n = 0
	for i in s:
		n += 1
		if i == '+':
			c += 1
		else:
			c -= 1
		if c < 0:
			a += n
			c += 1
	a += n
	print(a)
	t -= 1


from sys import exit, stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(T,) = rl()
for _ in range(T):
	s = input().rstrip()
	a = -1
	r = [0] * len(s)
	for (i, c) in enumerate(s):
		a += 1 if c == '-' else -1
		if a >= 0 and r[a] == 0:
			r[a] = i + 1
	print(sum(r) + len(s))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def sieve(a):
	for i in range(3, 10 ** 6 + 1, 2):
		a[i] = 1
	for i in range(3, 10 ** 6 + 1, 2):
		for j in range(i * i, 10 ** 6 + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def bfs(g, st):
	visited = [0] * len(g)
	visited[st] = 1
	queue = []
	queue.append(st)
	new = []
	while len(queue) != 0:
		s = queue.pop()
		new.append(s)
		for i in g[s]:
			if visited[i] == 0:
				visited[i] = 1
				queue.append(i)
	return new

def solve():
	s = inp()
	n = len(s)
	ans = []
	for i in range(0, n):
		if i == 0:
			if s[i] == '+':
				ans.append(1)
			else:
				ans.append(-1)
			continue
		if s[i] == '+':
			ans.append(ans[i - 1] + 1)
		else:
			ans.append(ans[i - 1] - 1)
	total = min(ans)
	cnt = [-1] * (abs(total) + 1)
	for i in range(0, len(ans)):
		if ans[i] < 0:
			if cnt[abs(ans[i])] == -1:
				cnt[abs(ans[i])] = i
	res = 0
	for i in range(0, abs(total) + 1):
		if i < abs(total):
			f = i + 1
			res += cnt[f] + 1
		else:
			res += n
	print(res)
testcase(int(inp()))


import math
for _ in range(int(input())):
	s = list(input())
	l = len(s)
	f = [0 for _ in range(l + 1)]
	cp = 0
	cn = 0
	for i in range(l):
		if s[i] == '+':
			cp += 1
		else:
			cn += 1
		if cn - cp > 0 and f[cn - cp] == 0:
			f[cn - cp] = i + 1
	print(sum(f) + l)


t = int(input())
while t:
	t -= 1
	array = list(input())
	ans = 0
	n = len(array)
	ans += n
	cur = 0
	cm = 0
	for i in range(n):
		if array[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < cm:
			ans += 1 + i
			cm = cur
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	S = list(input())[:-1]
	N = len(S)
	cs = [0] * (N + 1)
	for i in range(N):
		cs[i + 1] = cs[i] + 1 - 2 * (S[i] == '-')
	for i in range(N):
		cs[i + 1] = min(cs[i + 1], cs[i])
	res = 0
	x = 0
	for i in range(N + 1):
		if cs[i] < x:
			res += i
			x -= 1
	else:
		res += N
	print(res)


for t in range(int(input())):
	s = input()
	val = 0
	ans = 0
	cur = 0
	for i in range(len(s)):
		cur = min(cur, val)
		if s[i] == '+':
			val += 1
		else:
			val -= 1
		if val < 0 and val < cur:
			ans += i + 1
	ans += len(s)
	print(ans)


for i in range(int(input())):
	a = list(input())
	mcres = []
	cmcre = 0
	imcres = []
	cre = 0
	for i in range(len(a)):
		if a[i] == '+':
			cre += 1
		else:
			cre -= 1
		if cre < cmcre:
			cmcre = cre
			imcres.append(i)
			mcres.append(-cmcre)
	ans = 0
	pmcre = 0
	for i in range(len(mcres)):
		ans += (mcres[i] - pmcre) * (imcres[i] + 1)
		pmcre = mcres[i]
	ans += len(a)
	print(ans)


t = int(input())
for _ in range(t):
	seq = input()
	ct = 0
	reg = 0
	cur_min = 0
	ans = 0
	for i in seq:
		ct += 1
		if i == '+':
			reg += 1
		else:
			if reg == cur_min:
				ans += ct
				cur_min -= 1
			reg -= 1
	print(ans + len(seq))


t = int(input())
for x in range(t):
	s = input()
	L = []
	for i in s:
		L.append(int(i + '1'))
	for i in range(1, len(L)):
		L[i] = L[i] + L[i - 1]
	(i, ans, mim, j) = (0, 0, float('inf'), 0)
	while i < len(L):
		if j + L[i] == -1:
			j = j + 1
			ans = ans + i + 1
		i = i + 1
	print(ans + len(L))


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	cur = 0
	res = 0
	m = 0
	p = 0
	for z in range(0, n):
		if s[z] == '-':
			m += 1
			if m > p + cur:
				res += z + 1
				cur += 1
		if s[z] == '+':
			p += 1
	if p == 0:
		print(int(n + n * (n + 1) / 2))
	elif m == 0:
		print(n)
	else:
		res += n
		print(res)


query = int(input())
for i in range(query):
	s = list(input())
	cur = 0
	count = -1
	resc = 0
	for j in range(1, len(s) + 1):
		if s[j - 1] == '+':
			cur += 1
		else:
			cur -= 1
		if cur == count:
			resc += j
			count -= 1
		if j == len(s):
			resc += len(s)
	print(resc)


for _ in range(int(input())):
	s = input()
	n = len(s)
	m = 0
	ans = 0
	cnt = 0
	for i in range(n):
		if s[i] == '+':
			cnt += 1
		else:
			cnt -= 1
		if cnt < m:
			ans += i + 1
			m = cnt
	print(n + ans)


for j in range(int(input())):
	s = input()
	f = []
	if s[0] == '+':
		f.append(1)
	else:
		f.append(-1)
	u = 0
	for j in range(1, len(s)):
		if s[j] == '+':
			f.append(f[-1] + 1)
			u += 1
		else:
			f.append(f[-1] - 1)
			u -= 1
	ans = 0
	lest = 0
	for j in range(len(f)):
		if f[j] < lest:
			lest = f[j]
			ans += j + 1
	print(ans + len(s))


for _ in range(int(input())):
	s = input()
	m = 0
	r = 0
	sum = 0
	for (i, x) in enumerate(s):
		sum += 1 if x == '+' else -1
		if sum < m:
			m = sum
			r += i + 1
	print(r + len(s))


t = int(input())
for _ in range(t):
	s = input()
	res = 0
	nex = -1
	acc = 0
	for (i, c) in enumerate(s):
		acc += 1 if c == '+' else -1
		if acc == nex:
			res += i + 1
			nex -= 1
	res += len(s)
	print(str(res))


from collections import defaultdict
for _ in range(int(input())):
	a = input()
	d = defaultdict(lambda : 0)
	s = 0
	c = 0
	for i in range(0, len(a)):
		if a[i] == '-':
			c = c - 1
			if d[c] == 0 and c < 0:
				d[c] = 1
				s = s + i + 1
		else:
			c = c + 1
	s = s + len(a)
	print(s)


import sys
sys.setrecursionlimit(10000)
t = int(input())
for _ in range(t):
	s = input()
	mindiff = 0
	plus = 0
	all_lens = []
	minus = 0
	res_len = 0
	for achar in s:
		if achar == '+':
			plus += 1
		else:
			minus += 1
		if plus - minus < mindiff:
			mindiff = plus - minus
			res_len = plus + minus
			all_lens.append([mindiff, res_len])
	res = 0
	ind = 0
	for cur in range(-mindiff):
		while True:
			if ind == len(all_lens):
				res += all_lens[-1][1]
				break
			elif cur + all_lens[ind][0] < 0:
				res += all_lens[ind][1]
				break
			else:
				ind += 1
	res += len(s)
	print(res)


import sys
import math
from collections import defaultdict, deque
import heapq
mod = 10 ** 9 + 7
t = int(sys.stdin.readline())
for _ in range(t):
	l = sys.stdin.readline()[:-1]
	s = 0
	cnt = 0
	res = 0
	cur = 0
	i = 0
	n = len(l)
	num = 0
	while i < n:
		res += 1
		if l[i] == '+':
			cur += 1
		else:
			cur -= 1
			if cur < 0:
				while cur < 0:
					num += 1
					cur += 1
					res += i + 1
		i += 1
	print(res)


for _ in range(int(input())):
	s = str(input())
	res = 0
	tmp = 0
	cnt = 0
	for i in range(len(s)):
		if s[i] == '+':
			tmp += 1
		if s[i] == '-':
			tmp -= 1
		if tmp < res:
			cnt += i + 1
			res = tmp
	print(cnt + len(s))


n = int(input())
for _ in range(n):
	s = input()
	d = dict()
	sumi = 0
	minsum = 1000000000
	for i in range(len(s)):
		if s[i] == '-':
			sumi = sumi - 1
		if s[i] == '+':
			sumi = sumi + 1
		minsum = min(minsum, sumi)
		if sumi not in d.keys():
			d[sumi] = i
	ans = 0
	if minsum >= 0:
		print(len(s))
		continue
	ans = ans + len(s)
	for i in range(0, -1 * minsum):
		ans = ans + d[-1 * i - 1] + 1
	print(ans)


t = int(input())
for _ in range(t):
	s = list(input())
	res = len(s)
	dif = 0
	least = 0
	for i in range(len(s)):
		if s[i] == '+':
			dif += 1
		else:
			dif -= 1
			if dif < least:
				res += i + 1
				least = dif
	print(res)


t = int(input())
for case in range(t):
	s = input()
	n = len(s)
	vals = []
	life = 0
	res = 0
	prev = 0
	last_cur = 0
	for (index, i) in enumerate(s):
		life += int(i == '+')
		life -= int(i == '-')
		vals.append(life)
		if life < prev:
			res += (index + 1) * (abs(life) - last_cur)
			last_cur = abs(life)
			prev = life
	res += n
	print(res)


n = int(input())
for _ in range(n):
	s = input()
	a = [0] * len(s)
	a[0] = 1 if s[0] == '+' else -1
	for i in range(1, len(s)):
		a[i] = a[i - 1] + (1 if s[i] == '+' else -1)
	mn = 0
	for x in a:
		mn = min(mn, x)
	l = 0
	r = -mn
	res = 0
	for i in range(len(s)):
		res += r - l + 1
		l = max(l, -a[i])
	print(res)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	ss = input()
	sums = [0]
	for s in ss:
		sums.append(sums[-1] + (1 if s == '+' else -1))
	tot = 0
	mn = 0
	for (i, s) in enumerate(sums):
		if s < mn:
			tot += i
			mn = s
	tot += len(ss)
	print(tot)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


t = int(input())
for testcase in range(t):
	s = input()
	n = len(s)
	cur = 0
	res = 0
	arr = [0] * n
	for i in range(n):
		if s[i] == '-':
			if cur < 0:
				arr[i] = i + 1
			else:
				arr[i] = 1
			cur -= 1
		elif cur < 0:
			arr[i] = i + 1
			cur = 1
		else:
			arr[i] = 1
			cur += 1
	if cur < 0:
		res += n
	for i in range(n):
		res += arr[i]
	print(res, '\n')


t = int(input())
for _ in range(t):
	l = list(input())
	cur = 0
	ans = 0
	for i in range(len(l)):
		if l[i] == '+' and cur <= 0:
			cur = 1
		elif l[i] == '+':
			cur += 1
		if l[i] == '-':
			cur -= 1
		if cur < 0:
			ans += i + 1
	print(ans + len(l))


t = int(input())
for _ in range(t):
	a = input()
	n = len(a)
	ans = 0
	res = 0
	add = 0
	for i in range(n):
		if a[i] == '+':
			res += 1
		else:
			res -= 1
		if res + add < 0:
			add += 1
			ans += i + 1
	print(ans + n)


for _ in range(int(input())):
	s = input()
	n = len(s)
	d = [0] * (n + 1)
	it = 0
	for i in range(n):
		if s[i] == '-':
			it += 1
		else:
			it -= 1
		if d[it] == 0 and it > 0:
			d[it] = i + 1
	ans = n
	for x in range(1, n + 1):
		if d[x] == 0:
			break
		ans += d[x]
	print(ans)


t = int(input())
for _ in range(t):
	str = input()
	curr = 0
	ans = 0
	for i in range(len(str)):
		if str[i] == '-':
			curr -= 1
		else:
			curr = curr + 1
		if curr < 0:
			ans += i + 1
			curr = 0
	ans += len(str)
	print(ans)


for _ in range(int(input())):
	a = input()
	n = len(a)
	l = []
	c = 0
	ans = 0
	for i in range(n):
		if l == []:
			l.append(a[i])
			continue
		if a[i] == '-' and l[-1] == '+':
			l.pop()
		else:
			l.append(a[i])
	for i in range(len(l)):
		if l[i] == '+':
			break
	k = l.count('-')
	p = 1
	for i in range(n):
		if a[i] == '+':
			c += 1
		else:
			c -= 1
		if -c == p:
			ans += i + 1
			p += 1
		if p == k + 1:
			break
	ans += n
	print(ans)


from collections import defaultdict

def func(s):
	minm = 100
	l = len(s)
	chck = 0
	d = defaultdict(int)
	for (j, i) in enumerate(s, 1):
		if i == '+':
			chck += 1
		else:
			chck -= 1
		if chck < minm:
			minm = chck
		if chck not in d:
			d[chck] = j
	result = 0
	for i in range(1, abs(minm) + 1):
		result += d[-i]
	result += l
	print(result)
t = int(input())
for i in range(t):
	s = input()
	func(s)


for _ in range(int(input())):
	s = input()
	n = len(s)
	dp = [0] * n
	curr = 1 if s[0] == '+' else -1
	currmin = 0 if curr == 1 else curr
	for i in range(1, n):
		dp[i] = abs(currmin)
		if s[i] == '-':
			curr -= 1
		else:
			curr += 1
		currmin = min(curr, currmin)
	ans = n * dp[-1] - sum(dp) + n
	if curr + dp[-1] < 0:
		t = abs(curr) - dp[-1]
		ans += t * n
	print(ans)


T = int(input())
for test in range(T):
	s = input()
	res = 0
	cur = 0
	index = 0
	for i in range(len(s)):
		if s[i] == '-':
			cur -= 1
		else:
			cur += 1
		if cur < 0:
			res += i + 1
			cur += 1
	print(res + len(s))


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	s = input()
	n = len(s)
	h = {}
	cnt = 0
	mx = INF
	for i in range(n):
		if s[i] == '+':
			cnt += 1
		else:
			cnt -= 1
		if cnt < mx:
			mx = cnt
		if cnt not in h:
			h[cnt] = i + 1
	ans = 0
	mx *= -1
	for i in range(mx):
		ans += h[-(i + 1)]
	ans += n
	print(ans)
t = int(input())
for _ in range(t):
	main()


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	s = input()
	l = [0] * len(s)
	if s[0] == '+':
		l[0] = 1
	else:
		l[0] = -1
	for j in range(1, len(s)):
		l[j] += l[j - 1]
		if s[j] == '+':
			l[j] += 1
		else:
			l[j] -= 1
	ma = -1
	res = 0
	start = 0
	for j in range(len(s) + 1):
		flag = 0
		while start < len(s):
			if j + l[start] < 0:
				res += start + 1
				flag = 1
				break
			start += 1
		if flag == 0:
			res += start
			break
		start += 1
	print(res)


for _ in range(int(input())):
	s = input()
	k = [0 for _ in range(len(s))]
	a = 0
	for i in range(len(s)):
		if s[i] == '+':
			a += 1
			k[i] = a
		else:
			a -= 1
			k[i] = a
	(s, a) = (len(s), -1)
	for i in range(len(k)):
		if k[i] == a:
			s += i + 1
			a -= 1
	print(s)


t = int(input())
for i in range(t):
	s = input()
	c = 0
	ar = [0] * (len(s) + 2)
	if s[0] == '+':
		ar[0] = 1
	else:
		ar[0] = -1
	for i in range(1, len(s)):
		if s[i] == '+':
			ar[i] = ar[i - 1] + 1
		else:
			ar[i] = ar[i - 1] - 1
	mn = 0
	for i in range(len(s)):
		if ar[i] < mn:
			c += i + 1
			mn = ar[i]
	print(c + len(s))


t = int(input())
while t > 0:
	t -= 1
	a = input()
	res = len(a)
	mn = 0
	bal = 0
	for i in range(len(a)):
		if a[i] == '+':
			bal += 1
		else:
			bal -= 1
		if bal < mn:
			mn = bal
			res += i + 1
	print(res)


t = int(input())
for i in range(t):
	S = list(input())
	N = len(S)
	ans = 0
	a = 0
	k = 0
	if S[0] == '+':
		a = 1
	else:
		a = -1
		ans = 1
		k = 1
	b = 1
	for j in range(1, N):
		b += 1
		if S[j] == '-':
			a -= 1
		else:
			a += 1
		if a < -k:
			ans += b
			k += 1
	ans += b
	print(ans)


for _ in range(int(input())):
	s = input()
	c = 0
	a = -1
	r = 0
	for i in range(len(s)):
		if s[i] == '-':
			c -= 1
		else:
			c += 1
		if c == a:
			r += i + 1
			a -= 1
	print(r + len(s))


t = int(input())
for tt in range(0, t):
	s = input()
	diff = 0
	a = []
	b = []
	for i in range(0, len(s)):
		if s[i] == '-':
			diff = diff - 1
		else:
			diff = diff + 1
		a.append(diff)
		b.append([diff, i + 1])
	ans = 0
	b.sort()
	for i in range(0, len(s)):
		if b[i][0] < 0:
			if i == 0:
				ans += b[i][1]
			elif b[i - 1][0] != b[i][0]:
				ans += b[i][1]
		else:
			break
	print(ans + len(s))


def dif(pos, neg):
	return neg - pos
t = int(input())
for _ in range(t):
	string = input()
	arr = [0] * len(string)
	neg = 0
	pos = 0
	for i in range(len(string)):
		if string[i] == '+':
			pos += 1
			arr[i] = dif(pos, neg)
		else:
			neg += 1
			arr[i] = dif(pos, neg)
	res = 0
	maxi = 0
	for i in range(len(arr)):
		if arr[i] > maxi:
			maxi = arr[i]
			res += i + 1
	res += len(arr)
	print(res)


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin

def int_input():
	return list(map(int, input().split()))
t = int(input())
for ti in range(1, t + 1):
	s = input()
	res = 0
	cur = 0
	x = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < x:
			res += i + 1
			x = cur
	res += len(s)
	print(res)


for _ in range(int(input())):
	n = input()
	ans = 0
	count = 0
	pos = 0
	for i in n:
		count += 1
		if i is '-':
			if pos:
				pos -= 1
			else:
				ans += count
		else:
			pos += 1
	print(ans + count)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		s = input()
		le = len(s)
		res = 0
		lst = -1
		sb = 0
		ad = 0
		for i in range(le):
			if s[i] == '-':
				ad -= 1
				res += 1
				if ad < 0:
					ad = 0
					res += i + 1
			else:
				ad += 1
				res += 1
		print(res)
main()


inf = 1000000

def solve():
	s = list(input())
	res = 0
	a = 0
	for i in range(0, len(s)):
		if s[i] == '+':
			res = res + 1
			a = a + 1
		elif a > 0:
			res = res + 1
			a = a - 1
		else:
			res = res + i + 2
	print(res)
tc = int(input())
while tc > 0:
	solve()
	tc = tc - 1


import sys
input = sys.stdin.readline
for _ in range(int(input().rstrip())):
	data = input().rstrip()
	result = len(data)
	balance = 0
	for i in range(len(data)):
		if data[i] == '+':
			balance += 1
		else:
			balance -= 1
		if balance < 0:
			result += i + 1
			balance += 1
	print(result)


t = int(input())
for p in range(t):
	A = input()
	sum_far = 0
	cur = 0
	curr_ar = []
	curr_ar.append(0)
	if A[0] == '+':
		sum_far += 1
	else:
		sum_far -= 1
	if len(A) == 1:
		if sum_far < 0:
			curr_ar.append(1)
	for (i, j) in enumerate(A[1:]):
		if sum_far + cur < 0:
			curr_ar.append(cur + 1)
			cur += 1
		else:
			curr_ar.append(cur)
		if j == '+':
			sum_far += 1
		else:
			sum_far -= 1
		if i + 1 == len(A) - 1:
			if sum_far + cur < 0:
				curr_ar.append(cur + 1)
	pre = -3
	total = 0
	for (i, j) in enumerate(curr_ar[0:len(A)]):
		if pre < 0:
			pre = j
		elif pre != j:
			total += i
			pre = j
		if i == len(A) - 1:
			total += len(A)
	if len(curr_ar) > len(A):
		total += len(A)
	print(total)


from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	s = input()
	ans = len(s)
	loop = len(s) - s.count('+')
	if loop >= 1:
		var = 0
		d = {}
		ind = 0
		for i in s:
			if i == '-':
				var -= 1
			else:
				var += 1
			if var not in d:
				d[var] = ind
			if var + 2 < -1 * loop:
				break
			ind += 1
		varr = -1
		for j in range(loop):
			if varr not in d:
				break
			else:
				ans += d[varr] + 1
			varr -= 1
		print(ans)
	else:
		print(len(s))


t = int(input())
for x in range(t):
	s = input()
	res = 0
	worst = 0
	cur = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		if s[i] == '-':
			cur -= 1
		if cur < worst:
			res += i + 1
			worst = cur
	res += len(s)
	print(res)


import sys
readline = sys.stdin.readline

def solve():
	S = readline().rstrip()
	N = len(S)
	c0 = [0] * N
	for (i, c) in enumerate(S):
		if c == '+':
			c0[i] = c0[i - 1] + 1 if i > 0 else 1
		else:
			c0[i] = c0[i - 1] - 1 if i > 0 else -1
	ans = 0
	m = 0
	mi = -1
	for i in range(N):
		if c0[i] < m:
			lastm = m
			m = c0[i]
			mi = i
			ans += (i + 1) * (lastm - m)
	ans += N
	print(ans)
T = int(readline())
for i in range(T):
	solve()


def main():
	t = int(input())
	for _ in range(t):
		a = list(input())
		ans = len(a)
		s = 0
		power = 0
		for i in a:
			s += 1
			if i == '-':
				power -= 1
				if power < 0:
					power = 0
					ans += s
			else:
				power += 1
		print(ans)
main()


k = int(input())
while k > 0:
	k = k - 1
	s = input()
	t = 0
	v = 0
	for i in range(len(s)):
		if s[i] == '+':
			t += 1
		else:
			t -= 1
		if t < 0:
			v += i + 1
			t = 0
	print(v + len(s))


for _tes in range(int(input())):
	s = input()
	a = 0
	b = 0
	r = 0
	ans = 0
	for i in s:
		if i == '+':
			a += 1
		else:
			b += 1
			if b > a + r:
				ans += a + b
				r += 1
	ans += len(s)
	print(ans)


t = int(input())
testcases = list()
for i in range(t):
	testcases.append(input())
for testcase in testcases:
	s = testcase
	counter = 0
	res = 0
	for (i, c) in enumerate(s):
		counter += 1 if c == '+' else -1
		res += 1
		if counter < 0:
			counter = 0
			res += i + 1
	print(res)


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	s = input()
	n = len(s)
	first_instance_of_minus_i = [-1 for i in range(n + 1)]
	touched_minus_i = [False for i in range(n + 1)]
	cur = 0
	mini = 0
	for i in range(n):
		if s[i] == '+':
			cur = cur + 1
		else:
			cur = cur - 1
		if cur < 0:
			mini = min(cur, mini)
			val = -cur
			if touched_minus_i[val]:
				pass
			else:
				touched_minus_i[val] = True
				first_instance_of_minus_i[val] = i + 1
	ans = n
	for i in range(1, -mini + 1):
		ans += first_instance_of_minus_i[i]
	answers.append(ans)
print(*answers, sep='\n')


def check(k):
	if k == '+':
		return 1
	return -1
inf = 10 ** 12
for _ in range(int(input())):
	s = input()
	n = len(s)
	dp = [0] * (n + 1)
	for i in range(1, n + 1):
		dp[i] = dp[i - 1] + check(s[i - 1])
	d = {}
	for i in range(1, n + 1):
		if dp[i] < 0:
			d[dp[i]] = min(d.get(dp[i], inf), i)
	ans = 0
	for i in d:
		ans += d[i]
	ans += n
	print(ans)


def main():
	for t in range(int(input())):
		s = input()
		n = len(s)
		res = 0
		last = -1
		for i in range(n + 1):
			buf = 0
			for j in range(last + 1, n):
				if s[j] == '-':
					buf -= 1
				else:
					buf += 1
				if buf < 0:
					last = j
					res += last + 1
					break
			else:
				res += n
				last = n
				break
		print(res)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	ss = input()
	uu = 0
	ans = 0
	hh = 0
	cnt = 0
	xx = []
	for i in range(len(ss)):
		if ss[i] == '+':
			uu += 1
		else:
			uu -= 1
		if uu < 0:
			xx.append([uu, i + 1])
	xx.sort()
	if len(xx) < 1:
		print(len(ss))
		continue
	xx = sorted(xx, key=lambda xh: xh[1])
	for i in range(len(xx)):
		if abs(xx[i][0]) - hh > 0:
			ans += (abs(xx[i][0]) - hh) * xx[i][1]
			hh = 2 * abs(xx[i][0]) - abs(xx[i][0])
		else:
			cnt += 1
	print(ans + len(ss))


t = int(input())
buf = []
for _ in range(t):
	s = input()
	ans = 0
	cur = 0
	cur_min = 0
	for (i, c) in enumerate(s, start=1):
		if c == '+':
			cur += 1
			continue
		cur -= 1
		if cur < cur_min:
			ans += i
			cur_min = cur
	ans += len(s)
	buf.append(ans)
print('\n'.join(map(str, buf)))


import sys
from collections import deque
pprint = lambda s: print(' '.join(map(str, s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
for i in range(int(input())):
	m = 0
	slov = {'+': 1, '-': -1}
	s = list(map(lambda x: slov[x], input())) + [-100000000]
	n = len(s)
	k = 0
	summ = 0
	ans = 0
	for i in range(n):
		summ += s[i]
		if summ < 0:
			ans += i + 1
			summ += 1
	print(ans - 1)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	s = sys.stdin.readline().strip()
	len_s = len(s)
	list_check = [[0, 0] for _ in range(len_s + 1)]
	dict_pm = {'+': 0, '-': -1}
	for i in range(len_s):
		list_check[i][-1] += list_check[i - 1][-1]
		list_check[i][0] += list_check[i - 1][0]
		list_check[i][dict_pm[s[i]]] += 1
	res = 0
	c = 0
	for i in range(len_s):
		res += 1
		if list_check[i][0] + c < list_check[i][-1]:
			res += i + 1
			c = list_check[i][-1] - list_check[i][0]
	print(res)


for _ in range(int(input())):
	s = input()
	l = len(s)
	ps = [0] * l
	ef = [-1] * l
	if s[0] == '+':
		ps[0] = 1
	else:
		ps[0] = -1
	mv = ps[0]
	mi = 0
	for i in range(1, l):
		if s[i] == '+':
			ps[i] = ps[i - 1] + 1
		else:
			ps[i] = ps[i - 1] - 1
		if ps[i] < mv:
			ef[i] = abs(ps[i]) - 1
			mv = ps[i]
			mi = i
	if ps[0] == -1:
		ef[0] = 0
	su = 0
	for i in range(mi + 1):
		if ef[i] != -1:
			su += i + 1
	print(su + l)


debug = False
for _ in range(int(input())):
	s = input().strip()
	n = len(s)
	res = 0
	posInd = -1
	if s.count('+') > 0:
		posInd = s.index('+')
	if posInd == -1:
		print(n * (n + 1) // 2 + n)
	else:
		posCount = 0
		res = 0
		i = 1
		prevPosCount = -1
		for i in range(n):
			if debug:
				print('before', i, posCount, res)
			if posCount == 0 and (i == 0 or prevPosCount < 0):
				res += i + 1
			else:
				res += 1
			prevPosCount = posCount - 1
			if s[i] == '-':
				if i == n - 1 and posCount == 0:
					res += n
				posCount = max(posCount - 1, 0)
			else:
				posCount += 1
			if debug:
				print('After', i, posCount, res)
		print(res)


from sys import stdin, stdout
import sys
INF = 100000000000.0
import bisect

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
from collections import defaultdict
import math
for _ in range(int(stdin.readline())):
	s = get_string()
	curr = 0
	ans = []
	for i in range(len(s)):
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < 0:
			curr = 0
			ans.append(i + 1)
	ans.append(len(s))
	print(sum(ans))


t = int(input())
for _ in range(t):
	s = list(input().rstrip('\n'))
	count0 = 0
	count1 = 0
	total = 0
	flag = False
	for (i, each) in enumerate(s):
		if each == '-':
			if count1 > 0:
				total += 1
				count1 -= 1
			else:
				count0 += 1
				total += 1
				total += i + 1
		else:
			total += 1
			count1 += 1
	print(total)


for _ in range(int(input())):
	s = input()
	a = b = 0
	l = []
	mx = 0
	for i in range(len(s)):
		if s[i] == '+':
			a += 1
		else:
			b += 1
		if b > a and mx < b - a:
			l.append(i + 1)
			mx = b - a
	val = 0
	for i in l:
		val += i
	val += len(s)
	print(val)


test = int(input())
test_arr = []
for _ in range(test):
	string = str(input())
	(count1, count2) = (0, 0)
	i = 0
	count = 0
	k = 1
	for j in string:
		if j == '+':
			count1 += 1
		else:
			count2 += 1
		if count2 - (count1 + i) > 0:
			count += k
			i += 1
		k += 1
	if count > 0:
		count += len(string)
		test_arr.append(count)
	else:
		test_arr.append(len(string))
for t in test_arr:
	print(t)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	s = input()
	j = 0
	temp = 0
	ans = 0
	while True:
		if j == len(s):
			ans = ans + len(s)
			break
		if s[j] == '-':
			if temp == 0:
				ans += j + 1
				j += 1
			else:
				j += 1
				temp -= 1
		else:
			j += 1
			temp += 1
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	ans = 0
	cur = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			cur += 1
			ans += i + 1
	print(ans + len(s))


for _ in range(int(input())):
	a = input()
	(m, n) = (0, 0)
	l = len(a)
	for i in range(l):
		if a[i] == '-':
			m += 1
		else:
			n += 1
		if m > n:
			l += i + 1
			m -= 1
	print(l)


def check(dic, key):
	if key in dic.keys():
		return True
	else:
		return False
t = int(input())
while t > 0:
	t -= 1
	s = input()
	cnt = 0
	mx = 0
	res = 0
	dic = {}
	for i in range(len(s)):
		if s[i] == '+':
			cnt += 1
		else:
			cnt -= 1
		if cnt < 0 and check(dic, cnt) == False:
			dic[cnt] = i + 1
		mx = min(mx, cnt)
	mx *= -1
	for i in range(mx):
		res = res + dic[-(i + 1)]
	res += len(s)
	print(res)


for _ in range(int(input())):
	s = input()
	arr = {}
	cnt = 0
	ind = 0
	for x in s:
		if x == '-':
			cnt -= 1
			if cnt < 0 and cnt not in arr.keys():
				arr[cnt] = ind + 1
		else:
			cnt += 1
		ind += 1
	cur = 0
	res = 0
	keys = arr.keys()
	for i in range(1, ind + 1):
		if -i in keys:
			res += arr[-i]
		else:
			break
	print(res + ind)


def solve(s):
	n = len(s)
	res = 0
	cur = 0
	prev = 1
	for i in range(n):
		if s[i] == '-':
			cur -= 1
		else:
			cur += 1
		if cur < -prev + 1:
			res += i + 1
			prev += 1
	return res + n

def main():
	for i in range(int(input())):
		print(solve(input()))
main()


t = int(input())
for k in range(t):
	s = input()
	prev = 0
	minim = 0
	w = 0
	res = 0
	for (i, c) in enumerate(s):
		if c == '-':
			w -= 1
			if w < minim:
				minim = w
				res += i + 1
				prev = i
		else:
			w += 1
	print(res + len(s))


t = int(input())
for _ in range(t):
	str = input()
	pref = [1 if str[0] == '+' else -1]
	for i in range(1, len(str)):
		pref.append(pref[-1] + (1 if str[i] == '+' else -1))
	(res, ans) = (1, 0)
	for i in range(len(str) + 1):
		if i == len(str):
			ans += len(str)
			break
		elif pref[i] == res * -1:
			ans += i + 1
			res += 1
	print(ans)


from sys import stdin
for case in range(int(stdin.readline())):
	s = stdin.readline().strip()
	sumAt = [0]
	for x in s:
		if x == '+':
			sumAt.append(sumAt[-1] + 1)
		elif x == '-':
			sumAt.append(sumAt[-1] - 1)
	res = 0
	ind = 0
	init = 0
	ok = True
	while ok:
		while init + sumAt[ind] >= 0:
			ind += 1
			if ind == len(sumAt):
				ok = False
				break
		res += min(ind, len(s))
		init += 1
	print(res)


from collections import defaultdict as dd

def solve():
	s = list(input())
	n = len(s)
	ans = 0
	c = 0
	d = dd(lambda : 0)
	for i in range(n):
		if s[i] == '-':
			c -= 1
		else:
			c += 1
		if c < 0 and d[c] == 0:
			ans += i + 1
			d[c] = 1
	print(ans + n)
t = 1
t = int(input())
for _ in range(t):
	solve()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	string = input()
	first = {}
	cnt = 0
	for (ind, val) in enumerate(string):
		if val == '+':
			cnt += 1
		else:
			cnt -= 1
		if cnt < 0:
			if abs(cnt) not in first:
				first[abs(cnt)] = ind + 1
	ans = 0
	if len(first.keys()):
		mx = max(first.keys())
		for x in range(mx):
			ans += first[x + 1]
	print(len(string) + ans)


for _ in range(int(input())):
	s = input()
	x = [0]
	c = 0
	n = len(s)
	res = n
	for i in range(n):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
		if c < 0:
			res += i + 1
			c = 0
	print(res)


for T in range(int(input())):
	string = input()
	arr = [0] * len(string)
	s = 0
	least = 0
	total = 0
	for i in range(len(string)):
		if string[i] == '+':
			s += 1
		else:
			s -= 1
		if s < least:
			total += i + 1
			least = s
	print(total + len(string))


for _ in range(int(input())):
	s = input()
	low = 0
	cur = 0
	ans = 0
	for (i, c) in enumerate(s):
		ans += 1
		cur += 1 if c == '+' else -1
		if cur < low:
			low = cur
			ans += i + 1
	print(ans)


n = int(input())
for i in range(n):
	a = input()
	l = [0]
	m = [0]
	for j in range(len(a)):
		if a[j] == '+':
			l.append(l[-1] + 1)
		else:
			l.append(l[-1] - 1)
		if l[-1] <= len(m) * -1:
			m.append(j + 1)
	print(sum(m) + len(a))


from collections import defaultdict
con = 10 ** 9 + 7
INF = float('inf')

def getlist():
	return list(map(int, input().split()))

def main():
	T = int(input())
	for _ in range(T):
		s = input()
		N = len(s)
		S = [0] * (N + 1)
		Smin = [0] * (N + 1)
		for i in range(N):
			if s[i] == '+':
				S[i + 1] = S[i] + 1
			else:
				S[i + 1] = S[i] - 1
		for i in range(N):
			Smin[i + 1] = min(Smin[i], S[i + 1])
		ans = N
		for i in range(N):
			if Smin[i] > Smin[i + 1]:
				ans += i + 1
		print(ans)
main()


t = int(input())
for _ in range(t):
	s = str(input())
	n = len(s)
	pow = 0
	ans = n
	for i in range(n):
		if s[i] == '+':
			pow += 1
		else:
			pow -= 1
		if pow < 0:
			pow = 0
			ans = ans + i + 1
	print(ans)


for _ in range(int(input())):
	s = input()
	count = 0
	count1 = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '+':
			count += 1
		else:
			count -= 1
		if count < count1 and i != len(s):
			ans += i + 1
			count += 1
	print(ans + len(s))


from sys import stdin
t = int(input())
while t > 0:
	s = input()
	arr = []
	d = {}
	curr = 0
	for i in range(len(s)):
		if s[i] == '-':
			curr -= 1
			if curr not in d:
				d[curr] = i + 1
		else:
			curr += 1
	ans = 0
	for i in range(1, 10 ** 6 + 5):
		if -i in d:
			ans += d[-i]
		else:
			ans += len(s)
			break
	print(ans)
	t -= 1


import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(sys.stdin.readline())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def Solution():
	pass

def main():
	for _ in range(get_int()):
		s = get_string()
		n = len(s)
		total = 0
		ans = n
		i = 1
		for c in s:
			if c == '+':
				total += 1
			else:
				total -= 1
			if total < 0:
				ans += i
				total = 0
			i += 1
		print(ans)
main()


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	lol = [0] * (n + 1)
	if s[0] == '+':
		lol[0] = 1
	else:
		lol[0] = -1
	for i in range(1, len(s)):
		if s[i] == '+':
			lol[i] = lol[i - 1] + 1
		else:
			lol[i] = lol[i - 1] - 1
	res = 1
	ans = 0
	for i in range(0, n + 1):
		z = -1 * res
		if lol[i] == z and i != n:
			ans += i + 1
			res += 1
		elif i == n:
			ans += n
	print(ans)


T = int(input())
for _ in range(T):
	s = input().strip()
	n = len(s)
	running_sum = 0
	last_init = 0
	res = 0
	for (i, char) in enumerate(s):
		if char == '+':
			running_sum -= 1
		else:
			running_sum += 1
		if running_sum > last_init:
			res += i + 1
			last_init = running_sum
	print(res + n)


t = int(input())
for _ in range(t):
	s = list(input())
	cur = 0
	num = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			ans += i + 1
			cur = 0
	ans += len(s)
	print(ans)


import math
t = int(input(''))
while t > 0:
	s = list(input(''))
	plus_count = 0
	flag = 0
	base = len(s)
	ans = 0
	paths = []
	count = 0
	for j in range(0, len(s), 1):
		if s[j] == '-':
			if count == 0:
				paths.append(j + 1)
			elif count > 0:
				count -= 1
		else:
			count += 1
	ans = sum(paths) + base
	print(ans)
	t -= 1


from itertools import groupby
for _ in range(int(input())):
	s = list(input())
	n = len(s)
	Ans = 0
	cur = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			cur = 0
			Ans += i + 1
	if cur >= 0:
		Ans += n
	print(Ans)


t = int(input())
for _ in range(t):
	s = [i for i in input()]
	ans = 0
	res = 0
	cur = 0
	for i in range(len(s)):
		if s[i] == '+':
			ans += 1
		else:
			ans -= 1
		if ans < 0 and abs(ans) > cur:
			cur += 1
			res += i + 1
	res += len(s)
	print(res)


t = int(input())
for _ in range(t):
	s = input()
	last = s[0]
	ans = 0
	if s[0] == '-':
		ans = 2
		cur = 0
	else:
		ans = 1
		cur = 1
	for (i, v) in enumerate(s):
		if i >= 1:
			if cur == 0:
				if v == '+':
					cur += 1
					ans += 1
				else:
					ans += 2 + i
			else:
				ans += 1
				if v == '+':
					cur += 1
				else:
					cur -= 1
		last = v
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	res = 0
	cur_s = 0
	fl = 0
	for (i, el) in enumerate(s):
		if el == '-':
			cur_s = cur_s - 1
			if cur_s < 0:
				res += i + 1
				fl = 1
				cur_s = 0
		else:
			fl = 0
			cur_s += 1
	res += i + 1
	print(res)


for _ in range(int(input())):
	a = input()
	comp = 0
	init = 0
	for c in a:
		if c == '-':
			comp += 1
		else:
			comp -= 1
		if comp > init:
			init = comp
	if init <= 0:
		print(len(a))
		continue
	resp = 0
	count = 0
	add = init + 1
	for c in a:
		resp += add
		if c == '+':
			count += 1
		else:
			count -= 1
		if count < 0:
			add -= 1
			count = 0
	print(resp)


from collections import Counter
for _ in range(int(input())):
	(cur, last, res) = (0, 0, 0)
	s = input()
	for (i, c) in enumerate(s):
		if c == '+':
			cur -= 1
		elif c == '-':
			cur += 1
			if cur > last:
				res += (i + 1) * (cur - last)
				last = cur
	print(res + len(s))


import math as mt
import sys
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	s = input()
	n = len(s)
	pre = [0] * n
	a = []
	for i in range(n):
		a.append(1 if s[i] == '+' else -1)
	for i in range(1, n):
		a[i] += a[i - 1]
	cur = 0
	ans = 0
	for i in range(n):
		if cur + a[i] < 0:
			ans += i + 1
			cur += 1
	print(ans + n)


inf = 10000000
t = int(input())
for j in range(0, t):
	s = input()
	res = 0
	cur = 0
	ans = 0
	for i in range(0, len(s)):
		cur += 1
		ans += 1
		if s[i] == '+':
			res += 1
		else:
			res -= 1
		if res < 0:
			res += 1
			ans += cur
	print(ans)


import io
import os
from sys import stdout, stdin
input = stdin.readline
for _ in range(int(input())):
	s = input().strip()
	c = 0
	cur = 0
	temp = 0
	flag = 0
	for i in range(len(s)):
		c += 1
		if s[i] == '+':
			cur += 1
			flag += 1
		else:
			cur -= 1
			flag -= 1
		if cur < 0:
			c += i + 1
			temp += 1
			cur = temp + flag
	print(c)


for _ in range(int(input())):
	s = input()
	pref = []
	cur = 0
	for i in s:
		if i == '+':
			cur += 1
		else:
			cur -= 1
		pref.append(cur)
	(res, mn) = (0, 0)
	for i in range(len(pref)):
		if pref[i] < mn:
			mn = pref[i]
			res += i + 1
	print(res + len(s))


for _ in range(int(input())):
	s = input()
	s = list(s)
	n = len(s)
	count = 0
	pos = 0
	neg = 0
	for j in range(n):
		if s[j] == '-':
			neg += 1
		else:
			pos += 1
		if neg > pos:
			count += j + 1
			pos = 0
			neg = 0
	print(count + n)


for i in range(int(input())):
	s = str(input())
	cur = 0
	res = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			res += i + 1
			cur = 0
	print(res + len(s))


import sys
input = sys.stdin.readline

def solve(S):
	l = len(S)
	Acc = [0] * (l + 1)
	for (i, s) in enumerate(S):
		if s == '+':
			Acc[i + 1] = Acc[i] + 1
		else:
			Acc[i + 1] = Acc[i] - 1
	Cnt = [-1] * l
	ans = 0
	for i in range(1, l + 1):
		a = Acc[i]
		if a >= 0:
			continue
		Cnt[i - 1] = -a - 1
	if max(Cnt) == -1:
		return l
	Ans = [float('inf')] * (max(Cnt) + 1)
	for (i, cnt) in enumerate(Cnt):
		if cnt == -1:
			continue
		Ans[cnt] = min(i + 1, Ans[cnt])
	ans = l
	for a in Ans:
		if a == float('inf'):
			continue
		ans += a
	return ans

def main():
	t = int(input())
	for _ in range(t):
		S = input().strip()
		ans = solve(S)
		sys.stdout.write(str(ans) + '\n')
main()


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	l = [-1 if c == '-' else 1 for c in s]
	pre_sum = []
	current = 0
	for x in l:
		current += x
		pre_sum.append(current)
	f = [-1 for _ in range(n + 1)]
	for (i, x) in enumerate(pre_sum):
		if x < 0 and f[abs(x) - 1] == -1:
			f[abs(x) - 1] = i
	total = 0
	for x in f:
		if x == -1:
			total += n
			break
		else:
			total += x + 1
	print(total)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	s = input()
	a = []
	tot = 0
	for i in s:
		if i == '+':
			tot += 1
		else:
			tot -= 1
		a += [tot]
	di = {}
	for i in range(len(a)):
		if a[i] not in di:
			di[a[i]] = i + 1
	ans = 0
	tofind = -1
	while True:
		if tofind in di:
			ans += di[tofind]
			tofind -= 1
		else:
			ans += len(s)
			break
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	li = []
	if s[0] == '+':
		li.append(1)
	else:
		li.append(-1)
	for i in range(1, len(s)):
		if s[i] == '+':
			li.append(li[i - 1] + 1)
		else:
			li.append(li[i - 1] - 1)
	res = 0
	x = -1
	for i in range(len(li)):
		if li[i] == x:
			res = res + i + 1
			x -= 1
		else:
			res = res
	res = res + len(li)
	print(res)


from collections import deque
t = int(input())
from collections import defaultdict
for _ in range(t):
	s = input()
	n = len(s)
	arr = list(bytearray(n))
	hashmap = defaultdict(int)
	(temp, most_neg) = (0, 0)
	for (i, c) in enumerate(s):
		temp += 1 if c == '+' else -1
		arr[i] = temp
		if temp < 0 and temp not in hashmap:
			hashmap[temp] = i + 1
			if temp < most_neg:
				most_neg = temp
	res = 0
	for i in range(1, abs(most_neg) + 1):
		if -i in hashmap:
			res += hashmap[-i]
	res += n
	print(res)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		S = input().strip()
		accumu = [0] * len(S)
		for (i, s) in enumerate(S):
			if s == '+':
				accumu[i] = accumu[i - 1] + 1
			else:
				accumu[i] = accumu[i - 1] - 1
		score = 0
		current = -1
		for (i, a) in enumerate(accumu):
			if a == current:
				current -= 1
				score += i + 1
		score += len(S)
		print(score)
main()


t = int(input())
for _ in range(t):
	s = input()
	d = {}
	c = 0
	for i in range(len(s)):
		if s[i] == '-':
			c = c - 1
		else:
			c = c + 1
		if c not in d and c < 0:
			d[c] = i + 1
	p = len(s)
	for i in d:
		p = p + d[i]
	print(p)


for _ in range(int(input())):
	s = input()
	(p, m) = (0, 0)
	l = len(s)
	(c, res) = (0, 0)
	for i in range(l):
		if c == 0 and s[i] == '-':
			res += i + 2
		elif s[i] == '+':
			c += 1
			res += 1
		else:
			c -= 1
			res += 1
	print(res)


import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
tc = int(input())
for zz in range(tc):
	s = input()
	l = len(s)
	pl = 0
	mi = 0
	parr = [0] * l
	marr = [0] * l
	for i in range(l):
		if s[i] == '+':
			pl += 1
		else:
			mi += 1
		parr[i] = pl
		marr[i] = mi
	ans = 0
	seq = 0
	for i in range(l):
		if marr[i] > seq + parr[i]:
			ans += i + 1
			seq += 1
	print(ans + l)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
inf = 10 ** 18

def org(s):
	res = 0
	for init in range(10 ** 9):
		cur = init
		ok = True
		for i in range(len(s)):
			res += 1
			if s[i] == '+':
				cur = cur + 1
			else:
				cur = cur - 1
			if cur < 0:
				ok = False
				break
		if ok:
			break
	return res

def my(s):
	n = len(s)
	d = [inf] * (n + 2)
	c = 0
	for i in range(n):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
		if c < 0:
			d[-c] = min(d[-c], i)
	ans = 0
	for i in range(1, n + 2):
		if d[i] == inf:
			ans += n
			break
		else:
			ans += d[i] + 1
	return ans

def generate_case():
	for i in range(100):
		s = format(i, 'b').replace('1', '+').replace('0', '-')
		res1 = org(s)
		res2 = my(s)
		if res1 != res2:
			ws('{0}: {1} and {2}'.format(s, res1, res2))
			break

def solve(s):
	return my(s)

def main():
	for _ in range(ri()):
		s = rs()
		wi(solve(s))
main()


for _ in range(int(input())):
	s = input()
	n = len(s)
	cnt = [0] * n
	cur = 0
	for i in range(n):
		if s[i] == '+':
			cur = cur + 1
		else:
			cur = cur - 1
		cnt[i] = cur
	pos = -1
	pls = 0
	mn = 100000000
	ans = 0
	for i in range(n):
		cur = cnt[i] + pls
		if cur < 0:
			ans += (i + 1) * abs(cur)
			pls += abs(cur)
	print(ans + n)


t = int(input())
for _ in range(t):
	s = input()
	ans = 0
	tot = 0
	cutoff = 0
	for (i, c) in enumerate(s):
		if c == '+':
			tot += 1
		else:
			tot -= 1
		if tot < cutoff:
			ans += i + 1
			cutoff -= 1
	ans += len(s)
	print(ans)


import sys
import math
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
for t in range(int(input())):
	s = input()
	ans = len(s)
	a = 0
	checker = -1
	for i in range(len(s)):
		if s[i] == '-':
			a -= 1
		else:
			a += 1
		if a == checker:
			ans += i + 1
			checker -= 1
	print(ans)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [(ch, len(list(g))) for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def query(i, j, t):
	if t == 0:
		print('AND', i, j)
		sys.stdout.flush()
	elif t == 2:
		print('XOR', i, j)
		sys.stdout.flush()
	ans = N()
	return ans
t = N()
for i in range(t):
	s = input()
	cur = ans = 0
	d = set()
	for (i, ch) in enumerate(s, 1):
		if ch == '+':
			cur += 1
		else:
			cur -= 1
			if cur < 0 and cur not in d:
				ans += i
				d.add(cur)
	ans += len(s)
	print(ans)


import sys
input = sys.stdin.readline

def binary_search(i):
	(l, r) = (0, len(s))
	while l <= r:
		m = (l + r) // 2
		if i + acc[m] >= 0:
			l = m + 1
		else:
			r = m - 1
	return r
t = int(input())
for _ in range(t):
	s = input()[:-1]
	acc = [0]
	for i in range(len(s)):
		if s[i] == '+':
			acc.append(acc[-1] + 1)
		else:
			acc.append(acc[-1] - 1)
	for i in range(1, len(s) + 1):
		acc[i] = min(acc[i], acc[i - 1])
	ans = len(s)
	x = -acc[-1]
	for i in range(x):
		j = binary_search(i)
		ans += j + 1
	print(ans)


import sys
input = sys.stdin.readline

def solve(s):
	res = 0
	limit = 0
	cur = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		elif s[i] == '-':
			cur -= 1
		if cur < limit:
			res += i + 1
			limit -= 1
	return res + len(s)
t = int(input())
for _ in range(t):
	s = input().strip()
	print(solve(s))


t = int(input())
for _ in range(t):
	s = input()
	total = 0
	prefix_s = []
	for i in s:
		if i == '-':
			total -= 1
			prefix_s.append(total)
		else:
			total += 1
			prefix_s.append(total)
	minimum = min(0, min(prefix_s))
	maximum_number = abs(minimum)
	total = 0
	first_counts = {}
	for (ind, i) in enumerate(prefix_s):
		if i not in first_counts:
			first_counts[i] = ind
	for i in range(0, maximum_number):
		for j in range(i + 1, maximum_number + 1):
			if -j in first_counts:
				total += first_counts[-j] + 1
				break
	total += len(s)
	print(total)


t = int(input())
for _ in range(t):
	s = input()
	m = 0
	tmp = 0
	ans = []
	for (i, x) in enumerate(s):
		if x == '+':
			tmp += 1
		else:
			tmp -= 1
		if m > tmp:
			m = tmp
		if len(ans) < m * -1:
			ans.append(i + 1)
	ans = sum(ans) + len(s)
	print(ans)


for i in range(int(input())):
	s = input()
	arr = [0] * (len(s) + 1)
	su = 0
	for i in range(len(s)):
		if s[i] == '-':
			su -= 1
			arr[i] = su
		else:
			su += 1
			arr[i] = su
	g = -1
	t = 0
	for i in range(len(s)):
		if arr[i] == g:
			t += i + 1
			g -= 1
	print(t + len(s))


for _ in range(int(input())):
	s = input()
	l = []
	flag = 0
	n = len(s)
	cnt = 0
	ans = 0
	pre = -1
	start = 0
	l = []
	for i in range(n):
		if s[i] == '+':
			cnt += 1
		else:
			cnt -= 1
		l.append(cnt)
	pre = 0
	for i in range(len(l)):
		ans += 1
		if l[i] + pre < 0:
			ans += i + 1
			pre += 1
	print(ans)


from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def is_it_local():
	script_dir = str(os.getcwd()).split('/')
	username = 'dipta007'
	return username in script_dir

def READ(fileName):
	if is_it_local():
		sys.stdin = open(f'./{fileName}', 'r')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if not is_it_local():
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def input1(type=int):
	return type(input())

def input2(type=int):
	[a, b] = list(map(type, input().split()))
	return (a, b)

def input3(type=int):
	[a, b, c] = list(map(type, input().split()))
	return (a, b, c)

def input_array(type=int):
	return list(map(type, input().split()))

def input_string():
	s = input()
	return list(s)
if is_it_local():

	def debug(*args):
		st = ''
		for arg in args:
			st += f'{arg} '
		print(st)
else:

	def debug(*args):
		pass

def main():
	t = input1()
	for ci in range(t):
		st = input()
		cum = 0
		nw = 0
		res = 0
		ar = []
		mn = 0
		for (i, v) in enumerate(st):
			if v == '-':
				cum += -1
			else:
				cum += 1
			mn = min(mn, cum)
			ar.append((cum, -i))
		ar.sort(reverse=True)
		mx = -mn
		ind = 0
		for i in range(mx + 1):
			while ind < len(ar) and ar[ind][0] >= -i:
				ind += 1
			if ind < len(ar):
				res += -ar[ind][1] + 1
			else:
				res += len(ar)
		print(res)
	pass
main()


t = int(input().split()[0])
for i in range(t):
	s = str(input().split()[0])
	ans = 0
	diff = 0
	target = -1
	for j in range(len(s)):
		if s[j] == '+':
			diff += 1
		else:
			diff -= 1
		if diff == target:
			ans += j + 1
			target -= 1
	ans += len(s)
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = list(input().rstrip())
	nums = []
	c = 0
	lowest = 0
	total = 0
	for char in range(len(s)):
		if s[char] == '+':
			c += 1
		else:
			c -= 1
		if c < lowest:
			total += char + 1
		lowest = min(c, lowest)
	print(total + len(s))


from collections import defaultdict as dft
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	dct = dft(int)
	res = n
	curr = 0
	for i in range(n):
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < 0:
			if curr not in dct:
				dct[curr] = i + 1
	for (key, val) in dct.items():
		res += val
	print(res)


from sys import stdin
for _ in range(int(input())):
	s = list(input())
	if s[0] == '-':
		p = [-1]
	else:
		p = [1]
	for i in s[1:]:
		p.append(p[-1])
		if i == '-':
			p[-1] -= 1
		else:
			p[-1] += 1
	if min(p) >= 0:
		print(len(s))
		continue
	r = 0
	y = -1
	for i in range(len(p)):
		if p[i] == y:
			r += i + 1
			y -= 1
	print(r + len(s))


def main():
	dct = dict()
	line = input()
	num = 0
	for i in range(len(line)):
		if line[i] == '-':
			num -= 1
		else:
			num += 1
		if not num in dct:
			dct[num] = i + 1
	sm = 0
	for i in range(1, abs(min(dct.keys())) + 1):
		if -i in dct:
			sm += dct[-i]
	sm += len(line)
	print(sm)
t = int(input())
for i in range(t):
	main()


n = int(input())
for x in range(n):
	s = input()
	count = 0
	summ = 0
	a = []
	for (i, c) in enumerate(s):
		if c == '-':
			summ -= 1
		else:
			summ += 1
		if summ < 0:
			a.append((i, -summ))
	curr = 0
	for j in a:
		(x, y) = (j[0], j[1])
		if y > curr:
			count += (x + 1) * (y - curr)
			curr = y
	count += len(s)
	print(count)


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	res = 0
	plus = 0
	minus = 0
	for i in range(n):
		res += 1
		if s[i] == '+':
			plus += 1
		else:
			minus += 1
			if minus > plus:
				res += i + 1
				plus = 0
				minus = 0
	print(res)


t = int(input())
for i in range(t):
	st = input()
	x = y = 0
	n = len(st)
	for _ in range(len(st)):
		x += 1 if st[_] == '+' else -1
		if x < y:
			y = x
			n += _ + 1
	print(n)


t = int(input())
for _ in range(t):
	count = 0
	mincount = 0
	s = input()
	index = list()
	i = 0
	for i in range(len(s)):
		if s[i] == '+':
			count += 1
		else:
			count -= 1
		if mincount > count:
			index.append(i + 1)
			mincount = count
	print(len(s) + sum(index))


t = int(input())
while t > 0:
	t = t - 1
	s = input()
	n = len(s)
	pre = [0] * n
	f = [-1] * (n + 1)
	if s[0] == '-':
		pre[0] = -1
		f[1] = 1
	else:
		pre[0] = 1
	for i in range(1, n):
		if s[i] == '+':
			pre[i] = pre[i - 1] + 1
		else:
			pre[i] = pre[i - 1] - 1
		if pre[i] < 0:
			if f[-pre[i]] == -1:
				f[-pre[i]] = i + 1
	mini = pre[0]
	r = 0
	for i in range(n):
		if pre[i] < mini:
			mini = pre[i]
			r = i
	if mini >= 0:
		print(n)
	else:
		ans = n
		for j in range(0, -mini):
			ans = ans + f[j + 1]
		print(ans)


import array

def ans(s):
	counts = []
	count = 0
	for (i, c) in enumerate(s):
		if c == '-':
			count -= 1
		elif c == '+':
			count += 1
		else:
			assert False
		counts += [(count, i + 1)]
	counts += [(float('-inf'), len(s))]
	counts = sorted(counts) + [(0, 0)]
	prevCount = None
	ret = 0
	for (count, l) in counts:
		if count >= 0:
			break
		if count == prevCount:
			continue
		ret += l
		prevCount = count
	return ret
T = int(input())
for _ in range(T):
	s = input()
	print(ans(s))


for ad in range(int(input())):
	s = list(input())
	c = 0
	ans = len(s)
	x = -1
	for i in range(len(s)):
		if s[i] == '+':
			c += 1
		elif s[i] == '-':
			c -= 1
		if c == x:
			x -= 1
			ans += i + 1
	print(ans)


for _ in range(int(input())):
	s = input()
	(arr, k, res) = ([], 0, len(s))
	for i in s:
		k += -1 if i == '-' else 1
		arr.append(k)
	j = 0
	for i in range(1, len(s) + 1):
		while j < len(arr) and arr[j] > -1 * i:
			j += 1
		if j == len(s):
			break
		res += j + 1
	print(res)


t = int(input())
while t != 0:
	s = list(input())
	plus = 0
	minus = 0
	res = 0
	cur = 0
	init = 0
	for i in range(len(s)):
		if s[i] == '-':
			cur -= 1
		else:
			cur += 1
		if cur + init < 0:
			init += 1
			res += i + 1
	res += len(s)
	print(res)
	t -= 1


item = int(input())
for x in range(item):
	str = input()
	size = len(str)
	result = size
	temp = 0
	for i in range(size):
		if str[i] == '+':
			temp = temp + 1
		if str[i] == '-':
			temp = temp - 1
		if temp == -1:
			result = result + i + 1
			temp = 0
	print(result)


def solve():
	t = int(input())
	for i in range(t):
		s = input()
		n = len(s)
		acc = 0
		last_break = 0
		res = n
		for i in range(n):
			acc += 1 if s[i] == '+' else -1
			if acc < last_break:
				last_break = acc
				res += i + 1
		print(res)
solve()


from collections import deque
from sys import stdin, stdout
import math
input = stdin.readline
for _ in range(int(input())):
	x = input().strip()
	val = 0
	mn = 9999999
	for i in x:
		if i == '+':
			val += 1
		else:
			val -= 1
		mn = min(val, mn)
	if mn >= 0:
		print(len(x))
		continue
	mn -= 1
	res = 0
	val = 0
	wasmn = 99999999
	for i in x:
		wasmn = min(wasmn, val)
		if i == '+':
			val += 1
		else:
			val -= 1
		res += abs(mn - min(0, wasmn))
	print(res)


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	s = sin().strip()
	n = len(s)
	pre = [0] * n
	if s[0] == '+':
		pre[0] = 1
	else:
		pre[0] = -1
	for i in range(1, n):
		if s[i] == '+':
			x = 1
		else:
			x = -1
		pre[i] = pre[i - 1] + x
	if 1:
		d = dd(int)
		for i in range(n - 1, -1, -1):
			if pre[i] < 0:
				d[pre[i]] = i
		k = d.keys()
		k = sorted(k, reverse=True)
		ans = 0
		for i in k:
			ans += d[i] + 1
		ans += n
		print(ans)


t = int(input())
for _ in range(t):
	s = input()
	p = [0]
	p_min = 0
	res = 0
	for i in range(len(s)):
		if s[i] == '-':
			p.append(p[i] - 1)
			if p_min > p[i] - 1:
				res += i + 1
			p_min = min(p[i] - 1, p_min)
		else:
			p.append(p[i] + 1)
	res += len(s)
	print(res)


ans = []
for _ in range(int(input())):
	u = list(input())
	n = len(u)
	for i in range(n):
		if u[i] == '+':
			u[i] = 1
		else:
			u[i] = -1
	d = [0] * n
	cur = 0
	for i in range(n):
		cur += u[i]
		if cur < 0 and d[-cur - 1] == 0:
			d[-cur - 1] = i + 1
	ans.append(sum(d) + n)
print('\n'.join(map(str, ans)))


PUTIN_HELP_ME = not None
NAVALNY_HELP_ME = not None
DURKA_HELP_ME = not None
import sys, os, re
from math import *
from random import *

class Answer(BaseException):

	def __init__(self, txt):
		self.__text = txt

	def what(self):
		return self.__text

def answer(arg):
	raise Answer

def lcm(a, b: int):
	return a * b // gcd(a, b)

def readArr(modifier=int):
	return list(map(modifier, input().split()))

def rA(m=int):
	return readArr(m)

def chomp(s: str):
	return s[:-1] if s[-1] == '\n' else s

def readFile(name: str):
	f = open(name, 'r')
	r = f.readlines()
	f.close()
	return r

def init_all():
	sys.setrecursionlimit(max(sys.getrecursionlimit(), 500000))

def lower_bound(a, k):
	(l, r) = (0, len(a) - 1)
	while l != r:
		mid = (l + r) // 2
		if a[mid] < k:
			l = mid + 1
		else:
			r = mid
	return l

def upper_bound(a, k):
	(l, r) = (0, len(a) - 1)
	while l + 1 < r:
		mid = (l + r) // 2
		if a[mid] <= k:
			l = mid
		else:
			r = mid - 1
	if a[r] == k:
		return r
	else:
		return l

class poly_hash:

	def __init__(self, s):
		self.seed = 228
		self.M = 1000000007
		self.n = len(s)
		self.pows = [1]
		self.hsh = [0 for _ in range(self.n + 1)]
		for _ in range(self.n):
			self.pows.append(self.pows[-1] * self.seed % self.M)
		for i in range(self.n):
			self.hsh[i + 1] = (self.hsh[i] * self.seed + s[i]) % self.M

	def sub_hash(self, l, r):
		return (self.hsh[r] - self.hsh[l] * self.pows[r - l]) % self.M

def pre_func(s):
	p = [0]
	a = 0
	for i in range(1, len(s)):
		while a > 0 and s[i] != s[a]:
			a = p[a - 1]
		if s[i] == s[a]:
			a += 1
		p.append(a)
	return p

def solve():
	s = input()
	n = len(s)
	ans = n
	c = 0
	for i in range(n):
		if s[i] == '-':
			if c > 0:
				c -= 1
			else:
				ans += i + 1
		else:
			c += 1
	print(ans)

def main(argv: list):
	init_all()
	t = 1
	t = int(input())
	for _ in range(t):
		try:
			solve()
		except Answer as a:
			print(a.what())
	return 0
exit(main(sys.argv))


import math
import collections

def inpu():
	return input().split(' ')

def inti(a):
	for i in range(len(a)):
		a[i] = int(a[i])
	return a

def inp():
	a = inpu()
	a = inti(a)
	return a

def binary_search(arr, x):
	low = 0
	high = len(arr) - 1
	mid = 0
	while low <= high:
		mid = (high + low) // 2
		if arr[mid] < x:
			low = mid + 1
		elif arr[mid] > x:
			high = mid - 1
		else:
			return mid
	return -1
for _ in range(int(input())):
	a = input()
	n = len(a)
	s = [0] * n
	if a[0] == '-':
		s[0] = -1
	else:
		s[0] = 1
	for i in range(1, n):
		if a[i] == '-':
			s[i] = s[i - 1] - 1
		else:
			s[i] = s[i - 1] + 1
	val = min(s)
	count = -1
	ans = 0
	ptr = 0
	while count >= val:
		if s[ptr] == count:
			ans += ptr + 1
			count -= 1
		ptr += 1
	ans += n
	print(ans)


t = int(input())
for _ in range(t):
	ar = input()
	res = len(ar)
	cur = mi = 0
	for i in range(len(ar)):
		if ar[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < mi:
			res += i + 1
			mi = cur
	print(res)


t = int(input())
for i in range(t):
	s = input()
	counter = 1
	res = 0
	check = 0
	for j in s:
		if j == '-':
			check -= 1
		else:
			check += 1
		if check < 0:
			res += counter
			check = 0
		counter += 1
	res += counter - 1
	print(res)


from collections import *
import sys
from bisect import *
input = sys.stdin.readline
from math import *
t = int(input())
while t:
	t -= 1
	a = input().rstrip('\n')
	res = 0
	pp = 0
	i = 0
	while 1:
		cur = pp
		ok = True
		while i < len(a):
			if a[i] == '+':
				cur += 1
				i += 1
			else:
				cur -= 1
				i += 1
			if cur < 0:
				ok = False
				res += i
				break
		if ok:
			res += len(a)
			break
	print(res)


for _ in range(int(input())):
	s = input()
	n = len(s)
	sum_ = 0
	mn = 0
	ans = 0
	for i in range(n):
		sum_ += 1 if s[i] == '+' else -1
		if sum_ < mn:
			mn = sum_
			ans += i + 1
	ans += n
	print(ans)


def linput():
	return [int(i) for i in input().split()]

def nod(a, b):
	while a != 0 and b != 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	return a + b
qwertyyyyyy = int(input())
for ______ in range(qwertyyyyyy):
	s = input()
	res = 0
	cur = 0
	minc = 0
	ii = 0
	for i in range(len(s)):
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < minc:
			res += (i + 1) * (cur - minc) * -1
			minc = cur
			ii = i + 1
	print(res + len(s))


t = int(input())
for j in range(t):
	s = str(input())
	p = 0
	n = 0
	c = 0
	fp = -1
	pp = 0
	arr = []
	for i in range(len(s)):
		if s[i] == '+':
			p += 1
			if c == 0:
				c = 1
				fp = i
			pp += 1
		else:
			n += 1
			if c != 0:
				if pp == 0:
					arr.append(i)
				else:
					pp -= 1
	ans = len(s)
	if p == 0:
		x = n * (n + 1) / 2
		ans += x
	ans += fp * (fp + 1) / 2
	for i in range(len(arr)):
		ans += arr[i] + 1
	print(int(ans))


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	s = input().rstrip()
	ans = 0
	curr = 0
	for (i, sign) in enumerate(s):
		if sign == '+':
			curr += 1
		else:
			curr -= 1
		if curr < 0:
			curr = 0
			ans += i + 1
	ans += i + 1
	ans = str(ans)
	print(ans + '\n')


for _ in range(int(input())):
	s = list(input())
	(c, c1, count) = (0, 0, 0)
	for i in range(len(s)):
		if s[i] == '+':
			c += 1
		else:
			c1 += 1
		if c1 > c:
			c += 1
			count = count + i + 1
	print(count + len(s))


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	s = stdin.readline().rstrip()
	n = len(s)
	reqArr = [0]
	for i in range(n):
		if s[i] == '-':
			reqArr.append(reqArr[-1] - 1)
		else:
			reqArr.append(reqArr[-1] + 1)
	answer = 0
	req = min(reqArr)
	cur = 0
	toAdd = 0
	while cur + req < 0:
		toAdd = reqArr.index(-cur - 1, toAdd)
		answer += toAdd
		cur += 1
	answer += n
	print(answer)


def infnty():
	ix = 0
	while True:
		yield ix
		ix += 1

def sim(s):
	res = 0
	for init in infnty():
		cur = init
		ok = True
		for c in s:
			res += 1
			if c == '+':
				cur += 1
			elif c == '-':
				cur -= 1
			if cur < 0:
				ok = False
				break
		if ok:
			break
	return res

def sim2(s):
	res = 0
	net = 0
	for (i, c) in enumerate(s):
		res += 1
		if c == '-':
			if net <= 0:
				res += i + 1
			net -= 1
		if c == '+':
			if net < 0:
				net = 0
			net += 1
	return res
cases = ['--+-', '++--+-', '-', '--', '---', '----', '-----', '+', '++', '+++', '++++', '+++++', '+-', '+--', '+---', '-+', '-++', '-+++', '-+', '--+', '---+', '----+', '+-', '++-', '+++-', '++++-', '++-', '++--', '++---', '++----', '--+', '+-+', '-+-', '--++', '-++-', '+--+', '+-+-', '-+--', '---+-', '----+-', '---+--', '----+--', '---+-+--', '---+++-+-+---+--']
t = int(input().strip())
for _ in range(t):
	s = input().strip()
	print(sim2(s))


for _ in range(int(input())):
	S = input()
	ans = 0
	cur = 0
	s = 0
	for c in S:
		cur += 1
		s += 1 if c == '+' else -1
		if s < 0:
			s += 1
			ans += cur
	print(ans + cur)


q = int(input())
for _ in range(q):
	s = input()
	n = len(s)
	pref = [0] * n
	pref[0] = 1
	if s[0] == '-':
		pref[0] = -1
	for i in range(1, n):
		pref[i] = pref[i - 1] + (1 if s[i] == '+' else -1)
	pierszyminus = [-1] * (n + 1)
	for i in range(n):
		j = n - 1 - i
		if pref[j] < 0:
			pierszyminus[-pref[j]] = j
	wyn = 0
	for i in range(1, n + 1):
		wyn += pierszyminus[i] + 1
	wyn += n
	print(wyn)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
MOD = 10 ** 9 + 7
T = 1
T = int(stdin.readline())
for _ in range(T):
	s = str(stdin.readline().strip('\n'))
	n = len(s)
	cur = 0
	st = 0
	p = [0] * (n + 1)
	p[0] = 1
	for i in range(n):
		if s[i] == '-':
			cur -= 1
		elif s[i] == '+':
			cur += 1
		if cur + st < 0:
			p[0] += 1
			p[i + 1] -= 1
			st += 1
	res = 0
	for i in range(n):
		if i != 0:
			p[i] += p[i - 1]
		res += p[i]
	print(res)


for _ in range(int(input())):
	s = input()
	dp = [0] * (len(s) + 1)
	for i in range(1, len(s) + 1):
		dp[i] = dp[i - 1] + 1 if s[i - 1] == '+' else dp[i - 1] - 1
	res = len(s)
	inc = 0
	for i in range(1, len(dp)):
		if dp[i] + inc < 0:
			res += -(dp[i] + inc) * i
			inc = -dp[i]
	print(res)


t = int(input())
for case in range(t):
	s = input()
	a = []
	w = 0
	for i in s:
		if i == '+':
			w += 1
		else:
			w -= 1
		a.append(w)
	min = 0
	res = 0
	length = len(a)
	for i in range(length):
		if a[i] < min:
			min = a[i]
			res += i + 1
	res += length
	print(res)


def count(st):
	a = []
	res = 0
	if st[0] == '-':
		a.append(-1)
	else:
		a.append(1)
	for i in range(1, len(st)):
		if st[i] == '-':
			a.append(a[i - 1] - 1)
		else:
			a.append(a[i - 1] + 1)
	mydict = {}
	for i in range(len(st) - 1, -1, -1):
		mydict[a[i]] = i
	mini = min(a)
	for init in range(0, 2 * len(st)):
		if init + mini < 0:
			res += mydict[init + mini] + 1
		else:
			res += len(st)
			break
	return res
t = int(input())
for i in range(t):
	st = input()
	print(count(st))


for _ in range(int(input())):
	s = input()
	n = len(s)
	d = {}
	cnt = 0
	for (i, k) in enumerate(s):
		if k == '+':
			cnt += 1
		else:
			cnt -= 1
			if cnt < 0 and cnt not in d:
				d[cnt] = i + 1
	ans = sum(d.values()) + n
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	l = input()
	i = 0
	ans = 0
	f = 0
	cnt = 0
	while i < len(l) - 1:
		if l[i] == '+':
			cnt += 1
		else:
			cnt -= 1
		if cnt < 0:
			ans += i + 1
			cnt = 0
			if f == 0:
				f = 1
		i += 1
	print(ans + len(l) - 1)


import sys
import string
from heapq import *
from bisect import *
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import *
from itertools import accumulate
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
en = lambda x: list(enumerate(x))
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())

def solve():
	s = ip()
	c = 0
	ans = 0
	for (j, i) in enumerate(s, 1):
		c += 1 if i == '+' else -1
		if c < 0:
			ans += j
			c += 1
	print(ans + len(s))
for _ in range(ii()):
	solve()


z = input
from math import ceil
n = int(z())
for _ in range(n):
	l = z()
	n = len(l)
	r = 0
	c = 0
	j = 0
	for i in range(n):
		if l[i] == '+':
			c += 1
		if l[i] == '-':
			c -= 1
		if j > c:
			j = c
			n += i + 1
	print(n)


import sys
debug = False

def solve(pm):
	l = len(pm)
	profile = [0] * l
	cur = 0
	for i in range(l):
		cur += 1 if pm[i] == '+' else -1
		profile[i] = cur
	mn = min(profile)
	max_init = abs(mn)
	if debug:
		print(f'profile={profile}')
		print(f'max_init={max_init}')
	res_accum = 0
	if False:
		times_counted = max_init + 1
		for i in range(l):
			res_accum += times_counted
			if times_counted + profile[i] >= 0 and times_counted > 1:
				times_counted -= 1
	else:
		times_counted = 1 if mn >= 0 else max_init + 1
		next_decr = -1
		for i in range(l):
			res_accum += times_counted
			if debug:
				print(f'counting i={i}: times_counted={times_counted},res_accum={res_accum}')
			if profile[i] <= next_decr:
				next_decr -= 1
				times_counted -= 1
	return res_accum
IN = [x.strip() for x in sys.stdin.readlines()]
T = int(IN[0])
for ti in range(T):
	pm = [x for x in IN[1 + ti]]
	x = solve(pm)
	print(x)


import itertools
for _ in range(int(input())):
	s = input()
	res = 0
	cur = 0
	for i in range(len(s)):
		res = res + 1
		if s[i] == '+':
			cur = cur + 1
		else:
			cur = cur - 1
		if cur < 0:
			res += i + 1
			cur = 0
	print(res)


from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input()
	cumSum = [0]
	for c in s:
		newVal = 1 if c == '+' else -1
		cumSum.append(cumSum[-1] + newVal)
	minVal = min(cumSum)
	if minVal >= 0:
		print(len(s))
	else:
		indices = defaultdict(list)
		for (i, val) in enumerate(cumSum):
			indices[val].append(i)
		for val in indices.keys():
			indices[val].sort()
		minVal *= -1
		result = 0
		for i in range(minVal):
			target = -1 - i
			result += indices[target][0]
		print(result + len(s))


def solve(test):
	N = len(test)
	curr_opens = 0
	total = 0
	for i in range(N):
		if test[i] == '+':
			curr_opens += 1
		else:
			curr_opens -= 1
		if curr_opens < 0:
			total += i + 1
			curr_opens = 0
	return total + N

def main():
	T = int(input())
	for t in range(T):
		test = input().rstrip()
		print(solve(test))
main()


import sys
for _ in range(int(input())):
	a = input()
	(ans, cnt, minn) = (len(a), 0, 0)
	for i in range(len(a)):
		cnt += 1 if a[i] == '+' else -1
		if cnt < minn:
			minn = cnt
			ans += i + 1
	print(ans)


for i in range(int(input())):
	s = input()
	val = 0
	mini = 0
	j = 0
	ind = 0
	for i in s:
		if i == '+':
			val += 1
		else:
			val -= 1
		if val <= mini:
			mini = val
			ind = j
		j += 1
	if mini == 0:
		print(len(s))
		continue
	mini = abs(mini)
	l = [None] * (mini + 1)
	val = 0
	j = 0
	while j != ind + 1:
		if s[j] == '+':
			val += 1
		else:
			val -= 1
		if val < 0 and (not l[abs(val)]):
			l[abs(val)] = j + 1
		j += 1
	ans = 0
	for i in l:
		if i:
			ans += i
	print(ans + len(s))


import sys
input = lambda : sys.stdin.readline().rstrip()
from bisect import bisect_right
for _ in range(int(input())):
	s = input()
	ct = 0
	i = 0
	n = len(s)
	ans = 0
	d = {}
	while i < len(s):
		if s[i] == '+':
			ct += 1
		else:
			ct -= 1
		if ct < 0:
			v = -1 * ct
			if v not in d:
				d[v] = i + 1
		i += 1
	b = sorted(list(d.keys()))
	for i in range(n + 1):
		idx = bisect_right(b, i)
		if idx < len(b):
			ans += d[b[idx]]
		else:
			ans += n
			break
	print(ans)


t = int(input())
for _ in range(t):
	s = list(input())
	tot = 0
	cur = 0
	n = len(s)
	flag = 0
	for i in range(n):
		if s[i] == '+':
			cur = cur + 1
		else:
			cur = cur - 1
		if cur >= 0:
			continue
		else:
			flag = 1
			cur = cur + 1
			tot = tot + i + 1
	if flag == 0:
		print(n)
	else:
		tot = tot + n
		print(tot)


t = int(input())
for _ in range(t):
	s = input()
	ans = 0
	from collections import Counter
	c = Counter([])
	sumi = 0
	for i in range(len(s)):
		if s[i] == '+':
			sumi += 1
		else:
			sumi -= 1
		if c[sumi] == 0:
			c[sumi] = i + 1
	for i in range(len(s)):
		if c[-(i + 1)] == 0:
			break
		else:
			ans += c[-(i + 1)]
	print(ans + len(s))


def wa(s):
	return s.replace('()', '')

def ans(l, b):
	k = 0
	f = 0
	s = sum(l)
	x = s
	for i in range(1, 10000, 1):
		if s % b == 0:
			break
		s += 1
		f += 1
	print(f)
t = int(input())
while t > 0:
	s = str(input())
	mi = 0
	c = 0
	l = len(s)
	for i in range(len(s)):
		if s[i] == '+':
			c += 1
		else:
			c -= 1
		if c < mi:
			mi = c
			l += i + 1
	print(l)
	t -= 1


T = int(input())
while T > 0:
	T -= 1
	S = input()
	N = len(S)
	cur = 0
	ans = 0
	for i in range(0, N):
		if S[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			ans += i + 1
			cur += 1
	if cur >= 0:
		ans += N
	print(ans)


for _ in range(int(input())):
	s = input()
	res = 0
	neg = 0
	n = len(s)
	for i in range(n):
		if s[i] == '-':
			neg -= 1
		else:
			neg += 1
		if neg < 0:
			res += i + 1
			neg = 0
		if i == n - 1:
			res += n
	print(res)


from sys import *
input = stdin.readline
for _ in range(int(input())):
	s = input()
	s = s[:-1]
	cur = 0
	res = 0
	for i in range(len(s)):
		res += 1
		if s[i] == '+':
			cur += 1
		else:
			cur -= 1
		if cur < 0:
			res += i + 1
			cur = 0
	stdout.write(str(res) + '\n')


import math

def main_function():
	test_cases = range(int(input()))
	for test_case in test_cases:
		s = list(input())
		counter = 0
		min_val = 0
		collector = 0
		m = 0
		for i in range(len(s)):
			if s[i] == '-':
				counter -= 1
			else:
				counter += 1
			if counter < 0 and s[i] == '-':
				collector += i + 1
				counter += 1
				m = i + 1
		collector += len(s)
		print(collector)
main_function()


def solve(s):
	res = len(s)
	c1 = 0
	c0 = 0
	curr = 0
	j = 0
	for i in range(len(s)):
		if s[i] == '+':
			c1 += 1
			curr += 1
		else:
			c0 += 1
			curr -= 1
			if curr < 0:
				while curr < 0:
					j += 1
					curr = j - c0 + c1
				res += i + 1
	return res
t = int(input())
for we in range(t):
	s = input()
	print(solve(s))


from sys import stdin
input = lambda : stdin.readline().rstrip('\r\n')
from collections import defaultdict as vector
from collections import deque as que
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
Testcase = inin()
for _ in range(Testcase):
	s = input()
	curr = 0
	val = vector(lambda : float('inf'))
	for i in range(len(s)):
		if s[i] == '+':
			curr += 1
		else:
			curr -= 1
		if curr < 0:
			val[curr] = min(val[curr], i + 1)
	ans = len(s)
	for i in val:
		ans += val[i]
	print(ans)


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
(t,) = mp()
for _ in range(t):
	s = cin()[:-1]
	d = {'+': 1, '-': -1}
	res = x = 0
	n = len(s)
	l = [d[s[0]]]
	if l[0] < 0:
		res += 1
	for i in range(1, n):
		if s[i] == '+':
			l += [max(1 + l[-1], 1)]
		else:
			l += [l[-1] - 1]
			if l[-1] < 0:
				res += i + 1
	res += n
	cout(str(res) + '\n')


t = int(input())
while t:
	a = input()
	cur = 0
	init = 0
	res = 0
	(n, p) = (0, 0)
	for i in a:
		if i == '-':
			n += 1
		else:
			p += 1
	maxi = n
	for (i, v) in enumerate(a):
		if v == '-':
			cur -= 1
			if cur < 0:
				res += i + 1
				cur = 0
		else:
			cur += 1
	print(res + len(a))
	t -= 1


for _ in range(int(input())):
	ss = input()
	arr = [0] * len(ss)
	val = 0
	ind = 0
	for ch in ss:
		if ch == '+':
			val += 1
		else:
			val -= 1
		arr[ind] = val
		ind += 1
	ans = 0
	mn = 0
	for (ind, val) in enumerate(arr):
		if val < mn:
			ans += ind + 1
			mn = val
	ans += len(ss)
	print(ans)


def cin():
	return map(int, input().split())
for t in range(int(input())):
	s = input()
	n = len(s)
	pref = [0]
	l = float('inf')
	for c in s:
		pref.append(pref[-1] + (1, -1)[c == '-'])
		l = min(l, pref[-1])
	init = max(0, l * -1)
	ans = 0
	j = 1
	for i in range(init):
		while i + pref[j] >= 0:
			j += 1
		ans += j
		j += 1
	print(ans + n)


import sys
input = sys.stdin.readline
from math import ceil
ans = []
for kek in range(int(input())):
	s = input()
	m = 0
	a = 0
	j = 0
	for i in range(len(s)):
		if s[i] == '-':
			m += 1
		if s[i] == '+':
			m -= 1
		if j - m < 0:
			a += i + 1
			j += 1
	ans.append(a + len(s) - 1)
print(*ans, sep='\n')