Chef's friend Alex runs a movie theatre. Due to the increasing number of platforms for watching movies online, his business is not running well. As a friend, Alex asked Chef to help him maximise his profits. Since Chef is a busy person, he needs your help to support his friend Alex.  
Alex's theatre has four showtimes: 12 PM, 3 PM, 6 PM and 9 PM. He has four movies which he would like to play ― let's call them A, B, C and D. Each of these movies must be played exactly once and all four must be played at different showtimes. For each showtime, the price of a ticket must be one of the following: Rs 25, Rs 50, Rs 75 or Rs 100. The prices of tickets for different showtimes must also be different.
Through his app, Alex receives various requests from his customers. Each request has the form "I want to watch this movie at this showtime". Let's assume that the number of people who come to watch a movie at a given showtime is the same as the number of requests for that movie at that showtime.
It is not necessary to accommodate everyone's requests ― Alex just wants to earn the maximum amount of money. There is no restriction on the capacity of the theatre. However, for each movie that is not watched by anyone, Alex would suffer a loss of Rs 100 (deducted from the profit).
You are given $N$ requests Alex received during one day. Find the maximum amount of money he can earn on that day by choosing when to play which movies and with which prices. 

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- $N$ lines follow. Each of these lines contains a character $m$, followed by a space and an integer $t$, describing a request to see the movie $m$ at the showtime $t$.

-----Output-----
For each test case, print a single line containing one integer ― the maximum profit Alex can earn (possibly negative).
Finally, print a line containing one integer ― the total profit over all test cases, i.e. over $T$ days.

-----Constraints-----
- $1 \le T \le 150$
- $0 \le N \le 100$
- $m$ is 'A', 'B', 'C' or 'D'
- $t$ is $12$, $3$, $6$ or $9$

-----Subtasks-----
Subtask #1 (30 points): it is possible to fulfill all requests
Subtask #2 (70 points): original constraints

-----Example Input-----
5
12
A 3
B 12
C 6
A 9
B 12
C 12
D 3
B 9
D 3
B 12
B 9
C 6
7
A 9
A 9
B 6
C 3
D 12
A 9
B 6
2
A 9
B 6
1
D 12
0 

-----Example Output-----
575
525
-25 
-200 
-400
475

-----Explanation-----
Example case 1: The following table shows the number of people that want to watch the movies at the given showtimes:  12  3  6  9   A   0  1  0 1  B   3  0  0  2   C   1  0  2  0   D   0  2  0  0 
The maximum number of requests was sent for movie B at 12 PM. Therefore, we play this movie at this time and the tickets cost Rs 100. Next, we play movie D at 3 PM with ticket price Rs 75 and movie C at 6 PM with ticket price Rs 50. Finally, we have a slot for 9 PM and the only movie we can play at that time now is movie A, with ticket price Rs 25. The total profit is $3 \cdot 100 + 2 \cdot 75 + 2 \cdot 50 + 1 \cdot 25 = 300 + 150 + 100 + 25 = 575$. Since each movie was watched by at least one person, there is no additional loss.
Example case 2: Just like above, we show the requests in a table:  12  3  6  9   A   0  0  0 3  B   0  0  2  0   C   0  1  0  0   D   1  0  0  0 
The optimal solution is to play movie A at 9 PM, movie B at 6 PM, movie C at 3 PM and movie D at 12 PM, with decreasing ticket prices in this order. The profit is $3 \cdot 100 + 2 \cdot 75 + 1 \cdot 50 + 1 \cdot 25 = 300+150+50+25 = 525$.
Example case 3: Again, we show the requests in a table:  12  3  6  9   A   0  0  0 1  B   0  0  1  0   C   0  0  0  0   D   0  0  0  0 
The optimal solution is to play movie A at 9 PM with ticket price Rs 100, movie B at 6 PM with ticket price Rs 75 and the remaining two movies in any order at 12 PM and 3 PM ― either way, there will be nobody watching them. We earn $1 \cdot 100 + 1 \cdot 75 = 175$, but we have to deduct Rs 200, so the resulting profit is $175 - 200 = -25$.
Example case 4: The optimal solution is to play movie D at 12 PM; the other three movies go unattended. We have to deduct Rs 300, so the profit is $1 \cdot 100 - 300 = -200$.
Example case 5: Since there are no requests for any movie at any time, all movies go unattended and Alex just suffers a loss of Rs 400.
The total profit for all 5 days is $575+525-25-200-400 = 475$.

Difficulty: MEDIUM_HARD

Solutions:
ans = 0
for _ in range(int(input())):
	n = int(input())
	(A, B, C, D) = ([0] * 4, [0] * 4, [0] * 4, [0] * 4)
	for i in range(n):
		(m, t) = map(str, input().split())
		if m == 'A':
			if t == '12':
				A[0] += 1
			elif t == '3':
				A[1] += 1
			elif t == '6':
				A[2] += 1
			else:
				A[3] += 1
		elif m == 'B':
			if t == '12':
				B[0] += 1
			elif t == '3':
				B[1] += 1
			elif t == '6':
				B[2] += 1
			else:
				B[3] += 1
		elif m == 'C':
			if t == '12':
				C[0] += 1
			elif t == '3':
				C[1] += 1
			elif t == '6':
				C[2] += 1
			else:
				C[3] += 1
		elif t == '12':
			D[0] += 1
		elif t == '3':
			D[1] += 1
		elif t == '6':
			D[2] += 1
		else:
			D[3] += 1
	ans1 = -400
	for i in range(4):
		for j in range(4):
			if j == i:
				continue
			for k in range(4):
				if k == i or k == j:
					continue
				for l in range(4):
					if l == i or l == j or l == k:
						continue
					din = [A[i], B[j], C[k], D[l]]
					din.sort(reverse=True)
					count = 100 * din[0] + 75 * din[1] + 50 * din[2] + 25 * din[3]
					count -= 100 * din.count(0)
					if count > ans1:
						ans1 = count
	print(ans1)
	ans += ans1
print(ans)


from itertools import permutations as per
netsum = 0
for _ in range(int(input())):
	n = int(input())
	dic = {}
	for __ in range(n):
		(a, b) = input().split()
		if (a, b) not in dic:
			dic[a, b] = 1
		else:
			dic[a, b] += 1
	best = -10 ** 3
	for p in list(per(['A', 'B', 'C', 'D'])):
		profit = 0
		lc = []
		for tup in zip(p, ['12', '3', '6', '9']):
			lc.append(dic.get(tup, 0))
			if lc[-1] == 0:
				profit -= 100
		lc = sorted(lc)
		pr = 25
		for i in range(4):
			profit += lc[i] * pr
			pr += 25
		best = max(best, profit)
	print(best)
	netsum += best
print(netsum)


from itertools import permutations
l = list(permutations(range(0, 4)))
p = 0
t = int(input())
pft = 0
for i in range(t):
	A = {12: 0, 3: 0, 6: 0, 9: 0}
	B = {12: 0, 3: 0, 6: 0, 9: 0}
	C = {12: 0, 3: 0, 6: 0, 9: 0}
	D = {12: 0, 3: 0, 6: 0, 9: 0}
	n = int(input())
	for j in range(n):
		(m, t) = input().split()
		t = int(t)
		if m == 'A':
			A[t] += 1
		elif m == 'B':
			B[t] += 1
		elif m == 'C':
			C[t] += 1
		elif m == 'D':
			D[t] += 1
	ll = [[A[12], A[3], A[6], A[9]], [B[12], B[3], B[6], B[9]], [C[12], C[3], C[6], C[9]], [D[12], D[3], D[6], D[9]]]
	lp = []
	for i in l:
		lst = [ll[0][int(i[0])], ll[1][int(i[1])], ll[2][int(i[2])], ll[3][int(i[3])]]
		prc = 0
		pft = 0
		lst.sort()
		for mm in lst:
			prc += 25
			if mm == 0:
				pft = pft - 100
			else:
				pft = pft + mm * prc
		lp.append(pft)
	print(max(lp))
	p = p + max(lp)
print(p)


import sys
t = int(input())
tot = 0
while t:
	a = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
	n = int(input())
	for i in range(0, n):
		(m, q) = input().split()
		q = int(int(q) / 3 - 1)
		a[ord(m) - 65][q] += 1
	perm = [0, 1, 2, 3]
	cash = [100, 75, 50, 25]
	score = -sys.maxsize - 1
	for w in perm:
		perm1 = perm.copy()
		perm1.remove(w)
		for x in perm1:
			perm2 = perm1.copy()
			perm2.remove(x)
			for y in perm2:
				perm3 = perm2.copy()
				perm3.remove(y)
				for z in perm3:
					temp_score = 0
					val = [a[0][w], a[1][x], a[2][y], a[3][z]]
					val.sort(reverse=True)
					for i in range(0, 4):
						if val[i] == 0:
							temp_score -= 100
						else:
							temp_score += val[i] * cash[i]
					if temp_score >= score:
						score = temp_score
	print(score)
	tot += score
	t -= 1
print(tot)


def get_max(arr):
	t = sorted(arr, reverse=True)
	max = 0
	for (p, i) in enumerate(t):
		if p == 0:
			if i > 0:
				max = max + i * 100
			else:
				max -= 100
		elif p == 1:
			if i > 0:
				max = max + i * 75
			else:
				max -= 100
		elif p == 2:
			if i > 0:
				max = max + i * 50
			else:
				max -= 100
		elif p == 3:
			if i > 0:
				max = max + i * 25
			else:
				max -= 100
	return max

def set_values(arr, list_of_index):
	return [arr[0][list_of_index[0]], arr[1][list_of_index[1]], arr[2][list_of_index[2]], arr[3][list_of_index[3]]]

def calculate(arr):
	from itertools import permutations
	list_of_index = list(permutations([0, 1, 2, 3], 4))
	max_profit = get_max(list_of_index[0])
	max_list = []
	for i in list_of_index:
		max_list.append(get_max(set_values(arr, i)))
	return max(max_list)

def get_input(N):
	arr = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
	x = {'A': 0, 'B': 1, 'C': 2, 'D': 3}
	y = {'12': 0, '3': 1, '6': 2, '9': 3}
	max_list = []
	for i in range(N):
		ip = input()
		(x1, y1) = ip.split()
		arr[x[x1]][y[y1]] = arr[x[x1]][y[y1]] + 1
	return calculate(arr)
tc = input()
output = []
for i in range(int(tc)):
	N = input()
	max_val = get_input(int(N))
	output.append(max_val)
	print(max_val)
print(sum(output))


totals = []
for _ in range(int(input())):
	N = int(input())
	dp = [[0] * 4 for i in range(4)]
	converter = {'A': 0, 'B': 1, 'C': 2, 'D': 3, '12': 0, '3': 1, '6': 2, '9': 3}

	def smartsum(arr):
		z = sorted(arr, reverse=True)
		m = [25, 50, 75, 100]
		for i in range(len(z)):
			if z[i] == 0:
				z[i] = -100
			else:
				z[i] *= m.pop()
		return sum(z)

	def helper(dp, list_=[], sum_=0, depth=0, vals=[]):
		maxx = None
		if depth == 4:
			return vals
		for i in range(4):
			if i not in list_:
				new_sum = sum_ + dp[i][depth]
				x = helper(dp, list_ + [i], new_sum, depth + 1, vals + [dp[i][depth]])
				if maxx == None or smartsum(x) > smartsum(maxx):
					maxx = x
		return maxx
	for i in range(N):
		(A, B) = list(input().split())
		dp[converter[A]][converter[B]] += 1
	z = helper(dp)
	z.sort(reverse=True)
	m = [25, 50, 75, 100]
	for i in range(len(z)):
		if z[i] == 0:
			z[i] = -100
		else:
			z[i] *= m.pop()
	totals.append(sum(z))
	print(sum(z))
print(sum(totals))


from itertools import permutations
C = list(permutations(['A', 'B', 'C', 'D']))
V = list(permutations([3, 6, 9, 12]))
P = list(permutations([25, 50, 75, 100]))
R = []

def test():
	d = {}
	n = int(input())
	for i in C[0]:
		for j in V[0]:
			d[i + str(j)] = 0
	for i in range(n):
		(x, y) = input().split()
		d[x + y] += 1
	ans = -1000000000
	for i in C:
		for j in V:
			for k in P:
				c = 0
				for l in range(4):
					if d[i[l] + str(j[l])] == 0:
						c -= 100
					else:
						c += d[i[l] + str(j[l])] * k[l]
				ans = max(ans, c)
	R.append(ans)
	print(ans)

def __starting_point():
	t = int(input())
	for i in range(t):
		test()
	print(sum(R))
__starting_point()


from itertools import permutations

def solve(A):
	B = [A[12], A[3], A[6], A[9]]
	return B
t = int(input())
N = []
for _ in range(t):
	n = int(input())
	A = [0] * 13
	B = [0] * 13
	C = [0] * 13
	D = [0] * 13
	for i in range(n):
		(a, b) = map(str, input().split())
		if a == 'A':
			A[int(b)] += 1
		elif a == 'B':
			B[int(b)] += 1
		elif a == 'C':
			C[int(b)] += 1
		elif a == 'D':
			D[int(b)] += 1
	A = solve(A)
	B = solve(B)
	C = solve(C)
	D = solve(D)
	L = []
	P = list(permutations([0, 1, 2, 3]))
	for i in range(len(P)):
		(a, b, c, d) = P[i]
		M = [A[a], B[b], C[c], D[d]]
		M.sort()
		ans = M[0] * 25 + M[1] * 50 + M[2] * 75 + M[3] * 100
		if A[a] <= 0:
			ans -= 100
		if B[b] <= 0:
			ans -= 100
		if C[c] <= 0:
			ans -= 100
		if D[d] <= 0:
			ans -= 100
		L.append(ans)
	print(max(L))
	N.append(max(L))
print(sum(N))


from pprint import pprint
from numpy import where
arr = []
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	t = int(stdin.readline())
	a = []
	for i in range(4):
		temp = []
		for j in range(4):
			temp.append(0)
		a.append(temp)
	s = 0
	for __ in range(t):
		(mov, time) = input().split()
		time = int(time)
		if mov == 'A':
			if time == 12:
				a[0][0] += 1
			elif time == 3:
				a[0][1] += 1
			elif time == 6:
				a[0][2] += 1
			else:
				a[0][3] += 1
		elif mov == 'B':
			if time == 12:
				a[1][0] += 1
			elif time == 3:
				a[1][1] += 1
			elif time == 6:
				a[1][2] += 1
			else:
				a[1][3] += 1
		elif mov == 'C':
			if time == 12:
				a[2][0] += 1
			elif time == 3:
				a[2][1] += 1
			elif time == 6:
				a[2][2] += 1
			else:
				a[2][3] += 1
		elif time == 12:
			a[3][0] += 1
		elif time == 3:
			a[3][1] += 1
		elif time == 6:
			a[3][2] += 1
		else:
			a[3][3] += 1
	ma = -1
	cakes = []
	for k in range(4):
		(mai, maj) = (-1, -1)
		for i in range(4):
			for j in range(4):
				if a[i][j] > ma:
					ma = a[i][j]
					mai = i
					maj = j
		for z in range(4):
			for x in range(4):
				if z == mai or x == maj:
					a[z][x] = 0
		cakes.append(ma)
		ma = -1
	for i in range(len(cakes)):
		if cakes[i] == 0:
			s -= 100
		elif i == 0:
			s += cakes[i] * 100
		elif i == 1:
			s += cakes[i] * 75
		elif i == 2:
			s += cakes[i] * 50
		elif i == 3:
			s += cakes[i] * 25
	print(s)
	arr.append(s)
print(sum(arr))


max_profit = 0
for _ in range(int(input())):
	tt = []
	mr = []
	this_pro = -500
	for entry in range(4):
		tt.append([0] * 4)
	for r in range(int(input())):
		(movie, time) = map(str, input().split())
		time = int(time)
		if time == 12:
			time = 0
		else:
			time = (time + 12) // 3 - 4
		tt[ord(movie) - ord('A')][time] += 1
	for a in range(4):
		for b in range(4):
			for c in range(4):
				for d in range(4):
					if a != b and a != c and (a != d) and (b != c) and (b != d) and (c != d):
						mr = [tt[0][a], tt[1][b], tt[2][c], tt[3][d]]
						mr.sort()
						pro_scl = 100
						m_pro = 0
						for pro in range(3, -1, -1):
							if mr[pro] != 0:
								m_pro += mr[pro] * pro_scl
								pro_scl -= 25
							else:
								m_pro -= 100
						this_pro = max(this_pro, m_pro)
	print(this_pro)
	max_profit += this_pro
print(max_profit)


f = []
for ad in range(int(input())):
	n = int(input())
	a = [0] * 4
	b = [0] * 4
	c = [0] * 4
	d = [0] * 4
	for i in range(n):
		x = input().split()
		if x[0] == 'A':
			a[int(x[1]) // 3 - 1] += 1
		elif x[0] == 'B':
			b[int(x[1]) // 3 - 1] += 1
		elif x[0] == 'C':
			c[int(x[1]) // 3 - 1] += 1
		elif x[0] == 'D':
			d[int(x[1]) // 3 - 1] += 1
	x = []
	for i in range(4):
		for j in range(4):
			for k in range(4):
				for m in range(4):
					s = 0
					l = [i, j, k, m]
					if len(set(l)) == 4:
						y = [a[i], b[j], c[k], d[m]]
						for t in y:
							if t == 0:
								s -= 100
						y.sort()
						for t in range(3, -1, -1):
							s += (25 + 25 * t) * y[t]
						x.append(s)
	m = max(x)
	f.append(m)
	print(m)
print(sum(f))


from itertools import permutations
total_profit = 0
for _ in range(int(input())):
	times = {12: 0, 3: 1, 6: 2, 9: 3}
	movies = {'A': 0, 'B': 1, 'C': 2, 'D': 3}
	requests = [[0, 0, 0, 0] for i in range(4)]
	n = int(input())
	for _ in range(n):
		(a, b) = input().split()
		requests[movies[a]][times[int(b)]] += 1
	max_profit = -500
	for val in list(permutations([0, 1, 2, 3])):
		turnout = []
		for i in range(4):
			turnout.append(requests[i][val[i]])
		turnout = sorted(turnout)
		profit = sum([p * q for (p, q) in zip(turnout, [25, 50, 75, 100])])
		profit -= 100 * turnout.count(0)
		if profit > max_profit:
			max_profit = profit
	print(max_profit)
	total_profit += max_profit
print(total_profit)


import sys
t = int(input())
total = 0
for i in range(t):
	n = int(input())
	d = {'A': [0, 0, 0, 0], 'B': [0, 0, 0, 0], 'C': [0, 0, 0, 0], 'D': [0, 0, 0, 0]}
	for i in range(n):
		l = input().split()
		l1 = l[0]
		l2 = int(l[1]) // 3
		d[l1][l2 - 1] += 1
	maxx = -sys.maxsize - 1
	arr = {'A', 'B', 'C', 'D'}
	price = {25, 50, 75, 100}
	timing = {0, 1, 2, 3}
	for person1 in arr:
		for time1 in timing:
			for cost1 in price:
				summ1 = d[person1][time1] * cost1
				a = arr.copy()
				b = timing.copy()
				c = price.copy()
				a.remove(person1)
				b.remove(time1)
				c.remove(cost1)
				if d[person1][time1] == 0:
					summ1 = summ1 - 100
				for person2 in a:
					for time2 in b:
						for cost2 in c:
							summ2 = summ1 + d[person2][time2] * cost2
							e = a.copy()
							f = b.copy()
							g = c.copy()
							e.remove(person2)
							f.remove(time2)
							g.remove(cost2)
							if d[person2][time2] == 0:
								summ2 = summ2 - 100
							for person3 in e:
								for time3 in f:
									for cost3 in g:
										summ3 = summ2 + d[person3][time3] * cost3
										h = e.copy()
										i = f.copy()
										j = g.copy()
										h.remove(person3)
										i.remove(time3)
										j.remove(cost3)
										if d[person3][time3] == 0:
											summ3 = summ3 - 100
										for person4 in h:
											for time4 in i:
												for cost4 in j:
													summ4 = summ3 + d[person4][time4] * cost4
													if d[person4][time4] == 0:
														summ4 = summ4 - 100
													if summ4 > maxx:
														maxx = summ4
	print(maxx)
	total = total + maxx
print(total)


from itertools import permutations as p
k = list(p([12, 3, 6, 9]))
t = int(input())
fans = 0
for i in range(t):
	n = int(input())
	(A, B, C, D) = ({12: 0, 3: 0, 6: 0, 9: 0}, {12: 0, 3: 0, 6: 0, 9: 0}, {12: 0, 3: 0, 6: 0, 9: 0}, {12: 0, 3: 0, 6: 0, 9: 0})
	a = -400
	for j in range(n):
		(x, y) = map(str, input().split())
		if x == 'A':
			y = int(y)
			A[y] += 1
		if x == 'B':
			y = int(y)
			B[y] += 1
		if x == 'C':
			y = int(y)
			C[y] += 1
		if x == 'D':
			y = int(y)
			D[y] += 1
	for x in k:
		ans = 0
		l = []
		l.extend([A[x[0]], B[x[1]], C[x[2]], D[x[3]]])
		l.sort()
		ans = l[3] * 100 + l[2] * 75 + l[1] * 50 + l[0] * 25
		b = l.count(0)
		b = b * 100
		ans = ans - b
		if a < ans:
			a = ans
	print(a)
	fans = fans + a
print(fans)


from itertools import permutations
total = 0
for _ in range(int(input())):
	index_map = {12: 0, 3: 1, 6: 2, 9: 3}
	comb = permutations([i for i in range(4)])
	data = {chare: [0 for i in range(4)] for chare in ['A', 'B', 'C', 'D']}
	for i in range(int(input())):
		(movie, time) = input().split()
		data[movie][index_map[int(time)]] += 1
	profit = -400
	chars = ['A', 'B', 'C', 'D']
	for i in list(comb):
		ans = []
		for j in range(4):
			tempChar = chars[i[j]]
			ans.append(data[tempChar][j])
		ans.sort(reverse=True)
		temp = 0
		price = 100
		for i in ans:
			if i == 0:
				temp -= 100
			else:
				temp += i * price
				price -= 25
		if temp >= profit:
			profit = temp
	print(profit)
	total += profit
print(total)


ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
mp = lambda : map(int, input().split())
from itertools import permutations as p, product
ans = 0
for _ in range(int(input())):
	n = inp()
	dt = {}
	ti = {'12': 0, '3': 1, '6': 2, '9': 3}
	mov = {'A': 0, 'B': 1, 'C': 2, 'D': 3}
	price = [100, 75, 50, 25]
	for i in range(4):
		dt[i] = [0, 0, 0, 0]
	for i in range(n):
		(m, t) = input().split()
		dt[mov[m]][ti[t]] += 1
	var = list(p([0, 1, 2, 3]))
	temp = []
	for k in list(product(var, var)):
		(a, b) = k
		t = 0
		arr = [dt[a[i]][b[i]] for i in range(4)]
		arr.sort(reverse=True)
		for i in range(4):
			if arr[i] == 0:
				t -= 100
			else:
				t += arr[i] * price[i]
		temp.append(t)
	print(max(temp))
	ans += max(temp)
print(ans)


import numpy
from itertools import permutations
tots = 0
test = int(input())
while test != 0:
	n = int(input())
	tw = [0, 0, 0, 0]
	th = [0, 0, 0, 0]
	si = [0, 0, 0, 0]
	ni = [0, 0, 0, 0]
	s = [0, 1, 2, 3]
	for i in range(n):
		(m, t) = map(str, input().split())
		t = int(t)
		if m == 'A':
			ind = 0
		elif m == 'B':
			ind = 1
		elif m == 'C':
			ind = 2
		elif m == 'D':
			ind = 3
		if t == 12:
			tw[ind] += 1
		elif t == 3:
			th[ind] += 1
		elif t == 6:
			si[ind] += 1
		else:
			ni[ind] += 1
	co = list(permutations(s, 4))
	total = float('-inf')
	for value in co:
		p = [tw[value[0]], th[value[1]], si[value[2]], ni[value[3]]]
		p.sort(reverse=True)
		tot = 0
		for i in p:
			if i == 0:
				tot -= 100
		tot += p[0] * 100
		tot += p[1] * 75
		tot += p[2] * 50
		tot += p[3] * 25
		if tot > total:
			total = tot
	print(total)
	tots += total
	test -= 1
print(tots)


t_total = 0
for _ in range(int(input())):
	n = int(input())
	matrix = [[0 for i in range(4)] for i in range(4)]
	shows = {'A': 0, 'B': 1, 'C': 2, 'D': 3}
	times = {'12': 0, '3': 1, '6': 2, '9': 3}
	for z in range(n):
		(show, time) = input().strip().split()
		matrix[shows[show]][times[time]] += 1
	result = []
	import itertools
	ll = list(itertools.permutations([0, 1, 2, 3]))
	total = []
	for i in ll:
		result = [matrix[0][i[0]], matrix[1][i[1]], matrix[2][i[2]], matrix[3][i[3]]]
		result.sort(reverse=True)
		profit = 0
		money = [100, 75, 50, 25]
		j = 0
		for i in range(4):
			if result[i] == 0:
				profit -= 100
			else:
				profit += result[i] * money[j]
				j = j + 1
		total.append(profit)
	print(max(total))
	t_total += max(total)
print(t_total)


from sys import stdin

def theatre(arr):
	arr = sorted(arr, reverse=True)
	cost = 100 * arr[0] + 75 * arr[1] + 50 * arr[2] + 25 * arr[3]
	for i in range(4):
		if arr[i] == 0:
			cost -= 100
	return cost
prof = []
t = int(stdin.readline())
for i in range(t):
	arr = [[0 for i in range(4)] for j in range(4)]
	k = int(stdin.readline())
	maxi = -99999
	for j in range(k):
		(a, b) = stdin.readline().split(' ')
		b = int(b)
		arr[ord(a) - 65][b // 3 - 1] += 1
	for i in range(4):
		for j in range(4):
			if i == j:
				continue
			for k in range(4):
				if k == i or k == j:
					continue
				for l in range(4):
					if l == i or l == k or l == j:
						continue
					profit = theatre([arr[0][i], arr[1][j], arr[2][k], arr[3][l]])
					if profit > maxi:
						maxi = profit
	print(maxi)
	prof.append(maxi)
print(sum(prof))


from itertools import permutations
tot = []
t = int(input())
for _ in range(t):
	n = int(input())
	d = {'A3': 0, 'A6': 0, 'A9': 0, 'A12': 0, 'B3': 0, 'B6': 0, 'B9': 0, 'B12': 0, 'C3': 0, 'C6': 0, 'C9': 0, 'C12': 0, 'D3': 0, 'D6': 0, 'D9': 0, 'D12': 0}
	for _ in range(n):
		(m, t) = input().split()
		s = m + t
		d[s] += 1
	perms = permutations(['A', 'B', 'C', 'D'])
	mx = -400
	for p in perms:
		cost = [25, 50, 75, 100]
		views = []
		for i in range(len(p)):
			views.append(d[p[i] + str(3 * (i + 1))])
		views.sort()
		sm = 0
		for i in range(len(views)):
			v = views.pop()
			if v:
				sm += v * cost.pop()
			else:
				sm -= 100
		mx = max(mx, sm)
	tot.append(mx)
	print(mx)
print(sum(tot))


from itertools import permutations
from copy import deepcopy
perem = list(permutations([0, 1, 2, 3]))
time_to_index = {'12': 0, '3': 1, '6': 2, '9': 3}
movies = ['A', 'B', 'C', 'D']
times = [12, 3, 6, 9]
prices = [100, 75, 50, 25]
data = {}
for i in movies:
	data[i] = [0, 0, 0, 0]
total = 0
for tt in range(int(input())):
	theater = deepcopy(data)
	sm = 0
	maxval = -400
	for t in range(int(input())):
		(m, t) = input().split()
		theater[m][time_to_index[t]] += 1
	for i in perem:
		sm = 0
		arr = [theater['A'][i[0]], theater['B'][i[1]], theater['C'][i[2]], theater['D'][i[3]]]
		arr.sort(reverse=True)
		for j in range(4):
			if arr[j]:
				sm += arr[j] * prices[j]
			else:
				sm -= 100
		if sm > maxval:
			maxval = sm
	print(maxval)
	total += maxval
	if tt == 1:
		pass
print(total)


from itertools import permutations
total = 0
for _ in range(int(input())):
	n = int(input())
	tbl = []
	for i in range(4):
		tbl.append([0, 0, 0, 0])
	d = {'A': 0, 'B': 1, 'C': 2, 'D': 3, '12': 0, '3': 1, '6': 2, '9': 3}
	for i in range(n):
		(m, t) = input().split()
		tbl[d[m]][d[t]] += 1
	comb = permutations([0, 1, 2, 3])
	profit = -400
	for m in comb:
		temp = 0
		selected = []
		for t in range(4):
			selected.append(tbl[m[t]][t])
		selected.sort(reverse=True)
		price = 100
		for i in selected:
			if i > 0:
				temp += i * price
			else:
				temp -= 100
			price -= 25
		if temp > profit:
			profit = temp
	print(profit)
	total += profit
print(total)


T = int(input())
profit = 0
for _ in range(T):
	N = int(input())
	p = {'A': {12: 0, 3: 0, 6: 0, 9: 0}, 'B': {12: 0, 3: 0, 6: 0, 9: 0}, 'C': {12: 0, 3: 0, 6: 0, 9: 0}, 'D': {12: 0, 3: 0, 6: 0, 9: 0}}
	for i in range(N):
		a = input().split()
		m = a[0]
		t = int(a[1])
		p[m][t] += 1
	f = []
	for i in list(p.keys()):
		a = []
		for j in list(p[i].keys()):
			a.append(p[i][j])
		f.append(a)
	earn = -10000
	for i in range(4):
		for j in range(4):
			for k in range(4):
				for r in range(4):
					if i != j and j != k and (k != r) and (i != r) and (i != k) and (j != r):
						here = 0
						if f[0][i] == 0:
							here += 1
						if f[1][j] == 0:
							here += 1
						if f[2][k] == 0:
							here += 1
						if f[3][r] == 0:
							here += 1
						now = 0
						oo = [f[0][i], f[1][j], f[2][k], f[3][r]]
						oo.sort()
						for z in range(4):
							now += oo[4 - z - 1] * 25 * (4 - z)
						now -= here * 100
						earn = max(earn, now)
	print(earn)
	profit += earn
print(profit)


tp = 0
t = int(input())
i = 0
while i < t:
	n = int(input())
	a = [[0 for x in range(0, 4)] for y in range(0, 4)]
	for j in range(0, n):
		(m, tm) = input().split()
		tm = int(tm)
		if tm == 12:
			if m == 'A':
				a[0][0] += 1
			elif m == 'B':
				a[1][0] += 1
			elif m == 'C':
				a[2][0] += 1
			else:
				a[3][0] += 1
		elif tm == 3:
			if m == 'A':
				a[0][1] += 1
			elif m == 'B':
				a[1][1] += 1
			elif m == 'C':
				a[2][1] += 1
			else:
				a[3][1] += 1
		elif tm == 6:
			if m == 'A':
				a[0][2] += 1
			elif m == 'B':
				a[1][2] += 1
			elif m == 'C':
				a[2][2] += 1
			else:
				a[3][2] += 1
		elif tm == 9:
			if m == 'A':
				a[0][3] += 1
			elif m == 'B':
				a[1][3] += 1
			elif m == 'C':
				a[2][3] += 1
			else:
				a[3][3] += 1
	rl = 4
	cl = 4
	bc = 4
	p = 0
	pf = -500
	for i1 in range(0, 4):
		for i2 in range(0, 4):
			if i2 != i1:
				for i3 in range(0, 4):
					if i3 != i2 and i3 != i1:
						for i4 in range(0, 4):
							if i4 != i3 and i4 != i2 and (i4 != i1):
								list = [a[0][i1], a[1][i2], a[2][i3], a[3][i4]]
								p += 100 * max(list) - 100 * int(max(list) == 0)
								list.remove(max(list))
								p += 75 * max(list) - 100 * int(max(list) == 0)
								list.remove(max(list))
								p += 50 * max(list) - 100 * int(max(list) == 0)
								list.remove(max(list))
								p += 25 * max(list) - 100 * int(max(list) == 0)
								if p > pf:
									pf = p
								p = 0
	tp += pf
	print(pf)
	i = i + 1
print(tp)


from itertools import permutations
dict1 = {'A': 0, 'B': 1, 'C': 2, 'D': 3}
dict2 = {'3': 0, '6': 1, '9': 2, '12': 3}
dict3 = {0: 100, 1: 75, 2: 50, 3: 25}
sumOuter = 0
t = int(input())
for i in range(t):
	lst = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
	sumd = -400
	n = int(input())
	for j in range(n):
		(m, t) = input().split()
		lst[dict1[m]][dict2[t]] += 1
	for z in permutations(range(4)):
		val = [lst[0][z[0]], lst[1][z[1]], lst[2][z[2]], lst[3][z[3]]]
		val.sort(reverse=True)
		maxi = 0
		for n in range(4):
			if val[n] == 0:
				maxi -= 100
			else:
				maxi += val[n] * dict3[n]
		if maxi > sumd:
			sumd = maxi
	print(sumd)
	sumOuter += sumd
print(sumOuter)


import sys
finalAns = 0
for _ in range(int(input())):
	n = int(input())
	dic = {0: 100, 1: 75, 2: 50, 3: 25}
	timed = {'3': 0, '6': 1, '9': 2, '12': 3}
	(a, b, c, d) = ([0] * 4, [0] * 4, [0] * 4, [0] * 4)
	ans = -sys.maxsize
	for i in range(n):
		(typ, tim) = input().split()
		if typ == 'A':
			a[timed[tim]] += 1
		elif typ == 'B':
			b[timed[tim]] += 1
		elif typ == 'C':
			c[timed[tim]] += 1
		elif typ == 'D':
			d[timed[tim]] += 1
	for i in range(4):
		for j in range(4):
			for k in range(4):
				for l in range(4):
					if i == j or i == k or i == l or (j == k) or (j == l) or (k == l):
						continue
					temp = [a[i], b[j], c[k], d[l]]
					temp.sort(reverse=True)
					tempAns = 0
					for x in range(4):
						if temp[x] == 0:
							tempAns += -100
						else:
							tempAns += dic[x] * temp[x]
					ans = max(ans, tempAns)
	finalAns += ans
	print(ans)
print(finalAns)


from itertools import permutations
grandTotal = 0
for i in range(int(input())):
	n = int(input())
	time_slots = [12, 3, 6, 9]
	a = [0] * 4
	b = [0] * 4
	c = [0] * 4
	d = [0] * 4
	for i in range(n):
		(m, t) = map(str, input().split())
		idx = time_slots.index(int(t))
		if m == 'A':
			a[idx] += 1
		elif m == 'B':
			b[idx] += 1
		elif m == 'C':
			c[idx] += 1
		else:
			d[idx] += 1
	movies = ['A', 'B', 'C', 'D']
	allPermute = list(permutations(movies))
	ans = -100000000
	for permute in allPermute:
		total = 0
		curr_lis = []
		for (i, item) in enumerate(permute):
			if item == 'A':
				curr_lis.append(a[i])
			elif item == 'B':
				curr_lis.append(b[i])
			elif item == 'C':
				curr_lis.append(c[i])
			else:
				curr_lis.append(d[i])
		curr_lis.sort()
		ticket = 25
		for item in curr_lis:
			if item == 0:
				total -= 100
			else:
				total += item * ticket
			ticket += 25
		ans = max(ans, total)
	print(ans)
	grandTotal += ans
print(grandTotal)


def solve(movie, ind, used):
	if ind >= 4:
		arr = []
		for i in used:
			arr.append(used[i])
		arr.sort(reverse=True)
		profit = 0
		price = 100
		for i in arr:
			if i == 0:
				profit -= 100
				continue
			profit += price * i
			price -= 25
		nonlocal ans
		ans = max(ans, profit)
		return
	for i in movie[ind]:
		if i in used:
			continue
		used[i] = movie[ind][i]
		solve(movie, ind + 1, used)
		del used[i]
Test = int(input())
total = 0
for __ in range(Test):
	n = int(input())
	a = {3: 0, 6: 0, 9: 0, 12: 0}
	b = {3: 0, 6: 0, 9: 0, 12: 0}
	c = {3: 0, 6: 0, 9: 0, 12: 0}
	d = {3: 0, 6: 0, 9: 0, 12: 0}
	for i in range(n):
		arr = input().split()
		val = int(arr[1])
		if arr[0] == 'A':
			a[val] += 1
		elif arr[0] == 'B':
			b[val] += 1
		elif arr[0] == 'C':
			c[val] += 1
		else:
			d[val] += 1
		kdf = 'asdfasd'
		gasdf3 = 90877444
	ans = -2 ** 31
	solve([a, b, c, d], 0, {})
	print(ans)
	total += ans
print(total)


from itertools import permutations
l = list(permutations([3, 6, 9, 12]))
k = int(input())
w = []
for z in range(0, k):
	a = dict({3: 0, 6: 0, 9: 0, 12: 0})
	b = dict({3: 0, 6: 0, 9: 0, 12: 0})
	c = dict({3: 0, 6: 0, 9: 0, 12: 0})
	d = dict({3: 0, 6: 0, 9: 0, 12: 0})
	n = int(input())
	if n != 0:
		for i in range(0, n):
			(m, t) = input().split()
			t = int(t)
			if m == 'A':
				a[t] += 1
			elif m == 'B':
				b[t] += 1
			elif m == 'C':
				c[t] += 1
			elif m == 'D':
				d[t] += 1
		prof = []
		for i in l:
			i = list(i)
			x = list((a[i[0]], b[i[1]], c[i[2]], d[i[3]]))
			m = x.count(0)
			x.sort()
			profit = -100 * m + (x[0] * 25 + x[1] * 50 + x[2] * 75 + x[3] * 100)
			prof.append(profit)
		print(max(prof))
		w.append(max(prof))
	else:
		print('-400')
		w.append(-400)
print(sum(w))


from itertools import permutations
total_profit = 0
movie_name = {'A': 0, 'B': 1, 'C': 2, 'D': 3}
show_time = {12: 0, 3: 1, 6: 2, 9: 3}
index = [0, 1, 2, 3]
indx_perm = list(permutations(index))
T = int(input())
for _ in range(T):
	n = int(input())
	req = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
	for _ in range(n):
		(m, t) = [x for x in input().split()]
		t = int(t)
		req[movie_name[m]][show_time[t]] += 1
	profit = -400
	for p in indx_perm:
		temp = [req[movie_name[chr(65 + p[0])]][show_time[12]], req[movie_name[chr(65 + p[1])]][show_time[3]], req[movie_name[chr(65 + p[2])]][show_time[6]], req[movie_name[chr(65 + p[3])]][show_time[9]]]
		temp.sort(reverse=True)
		temp_profit = 0
		if temp[0] == 0:
			temp_profit -= 100
		else:
			temp_profit += 100 * temp[0]
		if temp[1] == 0:
			temp_profit -= 100
		else:
			temp_profit += 75 * temp[1]
		if temp[2] == 0:
			temp_profit -= 100
		else:
			temp_profit += 50 * temp[2]
		if temp[3] == 0:
			temp_profit -= 100
		else:
			temp_profit += 25 * temp[3]
		if temp_profit > profit:
			profit = temp_profit
	total_profit += profit
	print(profit)
print(total_profit)


from sys import stdin, stdout
I1 = lambda : int(stdin.readline())
T = 0
for _ in range(I1()):
	m = I1()
	li2 = [12, 3, 6, 9]
	d = {'A': [0, 0, 0, 0], 'B': [0, 0, 0, 0], 'C': [0, 0, 0, 0], 'D': [0, 0, 0, 0]}
	for i in range(m):
		(x, t) = map(str, stdin.readline().split())
		t = int(t)
		d[x][li2.index(t)] += 1
	n = 4
	ans = []
	cost = [100, 75, 50, 25]
	for i in range(n):
		li1 = []
		li1.append(d['A'][i])
		for j in range(n):
			if j != i:
				li1.append(d['B'][j])
				for k in range(n):
					if k != i and k != j:
						li1.append(d['C'][k])
						for l in range(n):
							if l != i and l != j and (l != k):
								li1.append(d['D'][l])
								c = 0
								z = 0
								for s in sorted(li1, reverse=True):
									if s == 0:
										c -= 100
									else:
										c += s * cost[z]
									z += 1
								if c != 0:
									ans.append(c)
								li1.pop()
						li1.pop()
				li1.pop()
		li1.pop()
	a = max(ans)
	print(a)
	T += a
print(T)


from itertools import permutations
import numpy as np

def update(str, arr):
	if str[0] == 'A':
		i = 0
	elif str[0] == 'B':
		i = 1
	if str[0] == 'C':
		i = 2
	if str[0] == 'D':
		i = 3
	if str[2:] == '12':
		j = 0
	elif str[2:] == '3':
		j = 1
	if str[2:] == '6':
		j = 2
	if str[2:] == '9':
		j = 3
	arr[i][j] += 1
T = int(input())
final_ans = 0
for i in range(T):
	ans = -float('inf')
	arr = np.zeros((4, 4))
	N = int(input())
	for j in range(N):
		x = str(input())
		update(x, arr)
	per = permutations([0, 1, 2, 3])
	for p in per:
		profit = -400
		l = []
		for ind in range(4):
			l.append(arr[ind][p[ind]])
			if arr[ind][p[ind]] != 0:
				profit += 100
		for ind in range(4):
			mini = min(l)
			profit += 25 * (ind + 1) * mini
			l.remove(mini)
		ans = int(max(ans, profit))
	print(ans)
	final_ans += ans
print(final_ans)


from pprint import pprint
from numpy import where
sum = 0
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	t = int(stdin.readline())
	a = []
	profit = -400
	for i in range(4):
		temp = []
		for j in range(4):
			temp.append(0)
		a.append(temp)
	price = [25, 50, 75, 100]
	cakes = [0, 0, 0, 0]
	for __ in range(t):
		(mov, time) = input().split()
		time = int(time)
		if mov == 'A':
			if time == 12:
				a[0][0] += 1
			elif time == 3:
				a[0][1] += 1
			elif time == 6:
				a[0][2] += 1
			else:
				a[0][3] += 1
		elif mov == 'B':
			if time == 12:
				a[1][0] += 1
			elif time == 3:
				a[1][1] += 1
			elif time == 6:
				a[1][2] += 1
			else:
				a[1][3] += 1
		elif mov == 'C':
			if time == 12:
				a[2][0] += 1
			elif time == 3:
				a[2][1] += 1
			elif time == 6:
				a[2][2] += 1
			else:
				a[2][3] += 1
		elif time == 12:
			a[3][0] += 1
		elif time == 3:
			a[3][1] += 1
		elif time == 6:
			a[3][2] += 1
		else:
			a[3][3] += 1
	for i in range(4):
		for j in range(4):
			for p in range(4):
				for q in range(4):
					if j != i and p != j and (p != i) and (q != j) and (q != i) and (q != p):
						cakes[0] = a[i][0]
						cakes[1] = a[j][1]
						cakes[2] = a[p][2]
						cakes[3] = a[q][3]
						cakes.sort()
						s = 0
						for c in range(0, 4):
							if cakes[c] != 0:
								s += cakes[c] * price[c]
							else:
								s -= 100
						if s >= profit:
							profit = s
	print(profit)
	sum += profit
print(sum)


f = 0
for _ in range(int(input())):
	n = int(input())
	arr = [[0] * 4, [0] * 4, [0] * 4, [0] * 4]
	for z in range(n):
		(m, t) = map(str, input().split())
		arr[65 - ord(m)][int(t) % 12 // 3] += 1
	ans = []
	for i in range(4):
		m = [arr[0][i]]
		for j in range(4):
			a = m[:]
			if j != i:
				m.append(arr[1][j])
				for k in range(4):
					b = m[:]
					if k != j and k != i:
						m.append(arr[2][k])
						for l in range(4):
							if l not in [i, j, k]:
								x = m[:]
								m.append(arr[3][l])
								m.sort()
								v = -100 * m.count(0) + 100 * m[-1] + 75 * m[-2] + 50 * m[1] + 25 * m[0]
								ans.append(v)
								m = x
					m = b
			m = a
	s = max(ans)
	print(s)
	f += s
print(f)


from itertools import permutations
total = 0
for a in range(int(input())):
	data = [0 for i in range(16)]
	index_map = {12: 0, 3: 1, 6: 2, 9: 3}
	indexes = [i for i in range(4)]
	comb = permutations(indexes)
	data = {}
	data['A'] = [0, 0, 0, 0]
	data['B'] = [0, 0, 0, 0]
	data['C'] = [0, 0, 0, 0]
	data['D'] = [0, 0, 0, 0]
	for i in range(int(input())):
		(movie, time) = input().split()
		data[movie][index_map[int(time)]] += 1
	counter = 0
	profit = -400
	for i in list(comb):
		ans = []
		for j in range(4):
			charac = chr(i[j] + 65)
			ans.append(data[charac][j])
		ans.sort(reverse=True)
		temp = 0
		price = 100
		for j in range(4):
			if ans[j] == 0:
				temp -= 100
			else:
				temp += ans[j] * price
				price -= 25
		if temp >= profit:
			profit = temp
	print(profit)
	total += profit
print(total)


from itertools import permutations
t = int(input())
t1 = 0
while t >= 1:
	t = t - 1
	n = int(input())
	A = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	B = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	C = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	D = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	for i in range(n):
		(a, b) = map(str, input().split())
		if a == 'A':
			A[int(b)] = A[int(b)] + 1
		elif a == 'B':
			B[int(b)] = B[int(b)] + 1
		elif a == 'C':
			C[int(b)] = C[int(b)] + 1
		else:
			D[int(b)] = D[int(b)] + 1
	p = permutations([A, B, C, D])
	t2 = 0
	m = []
	for i in p:
		l = [i[0][3], i[1][6], i[2][9], i[3][12]]
		l.sort()
		t2 = l[0] * 25 + l[1] * 50 + l[2] * 75 + l[3] * 100
		t2 = t2 - l.count(0) * 100
		m.append(t2)
	print(max(m))
	t1 = t1 + max(m)
print(t1)


def maximizing(array):
	cpy = array[:]
	final_list = []
	for i in range(len(array)):
		new_list = [array[i]]
		for t in range(len(cpy)):
			for j in range(len(new_list)):
				if cpy[t][0] == new_list[j][0] or cpy[t][1] == new_list[j][1]:
					break
			else:
				new_list.append(cpy[t])
		cpy.remove(array[i])
		final_list.append(new_list)
	costing = []
	for i in final_list:
		cost = 0
		count_array = []
		if len(i) < 4:
			cost -= (4 - len(i)) * 100
		for j in i:
			count_array.append(arrays.count(j))
		count_array.sort(reverse=True)
		threshold = 100
		for k in count_array:
			cost += k * threshold
			threshold -= 25
		costing.append(cost)
	return max(costing)
test_cases = int(input())
output_list = []
for _ in range(test_cases):
	n = int(input())
	arrays = []
	if n != 0:
		for _ in range(n):
			arrays.append(list(input().split()))
		output_list.append(maximizing(arrays))
	else:
		output_list.append(-400)
for output in output_list:
	print(output)
print(sum(output_list))


final = 0
from itertools import permutations
for _ in range(int(input())):
	su = 0
	n = int(input())
	t1 = [0 for i in range(4)]
	t2 = [0 for i in range(4)]
	t3 = [0 for i in range(4)]
	t4 = [0 for i in range(4)]
	per = [0, 1, 2, 3]
	for q in range(n):
		(x, k) = map(str, input().split())
		if x == 'A':
			z = 0
		elif x == 'B':
			z = 1
		elif x == 'C':
			z = 2
		else:
			z = 3
		if k == '12':
			t1[z] += 1
		elif k == '3':
			t2[z] += 1
		elif k == '6':
			t3[z] += 1
		elif k == '9':
			t4[z] += 1
	li = list(permutations(per))
	to = float('-inf')
	for b in li:
		p = [t1[b[0]], t2[b[1]], t3[b[2]], t4[b[3]]]
		p.sort(reverse=True)
		su = p[0] * 100 + p[1] * 75 + p[2] * 50 + p[3] * 25
		for i in range(4):
			if p[i] == 0:
				su = su - 100
		if su > to:
			to = su
	print(to)
	final += to
print(final)


def generateIndex(indexes):
	ans = indexes[:]
	for i in range(1, 4):
		for j in indexes:
			temp = []
			for k in j:
				temp.append((k + i) % 4)
			ans.append(temp)
	return ans

def countScore(x, index):
	profit = []
	for i in range(4):
		profit.append(x[i][index[i]])
	profit.sort()
	ans = 0
	m = [25, 50, 75, 100]
	for i in range(4):
		temp = m[i] * profit[i]
		if temp == 0:
			ans -= 100
		else:
			ans += temp
	return ans

def ind(t):
	if t == 3:
		return 0
	if t == 6:
		return 1
	if t == 9:
		return 2
	if t == 12:
		return 3
t = int(input())
total = 0
while t > 0:
	indexes = [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1]]
	allIndex = generateIndex(indexes)
	t -= 1
	n = int(input())
	a = [0, 0, 0, 0]
	b = a[:]
	c = a[:]
	d = a[:]
	for _ in range(n):
		(m, t1) = input().split()
		t1 = int(t1)
		if m == 'A':
			a[ind(t1)] += 1
		elif m == 'B':
			b[ind(t1)] += 1
		elif m == 'C':
			c[ind(t1)] += 1
		else:
			d[ind(t1)] += 1
	x = [a, b, c, d]
	ans = []
	for i in allIndex:
		ans.append(countScore(x, i))
	profit = max(ans)
	total += profit
	print(profit)
print(total)


t = int(input())
sum = 0
for _ in range(t):
	profit = -400
	count = 0
	n = int(input())
	v = [25, 50, 75, 100]
	k = [0, 0, 0, 0]
	l = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
	for _ in range(n):
		(a, b) = map(str, input().split())
		if a == 'A':
			if b == '12':
				l[0][0] += 1
			elif b == '3':
				l[1][0] += 1
			elif b == '6':
				l[2][0] += 1
			else:
				l[3][0] += 1
		elif a == 'B':
			if b == '12':
				l[0][1] += 1
			elif b == '3':
				l[1][1] += 1
			elif b == '6':
				l[2][1] += 1
			else:
				l[3][1] += 1
		elif a == 'C':
			if b == '12':
				l[0][2] += 1
			elif b == '3':
				l[1][2] += 1
			elif b == '6':
				l[2][2] += 1
			else:
				l[3][2] += 1
		elif b == '12':
			l[0][3] += 1
		elif b == '3':
			l[1][3] += 1
		elif b == '6':
			l[2][3] += 1
		else:
			l[3][3] += 1
	for i in range(4):
		for j in range(4):
			for p in range(4):
				for q in range(4):
					if j != i and p != j and (p != i) and (q != j) and (q != i) and (q != p):
						k[0] = l[i][0]
						k[1] = l[j][1]
						k[2] = l[p][2]
						k[3] = l[q][3]
						k.sort()
						temp = 0
						for x in range(0, 4):
							if k[x] != 0:
								temp += v[x] * k[x]
							else:
								temp -= 100
						if temp >= profit:
							profit = temp
	print(profit)
	sum = sum + profit
print(sum)


tp = 0
for _ in range(int(input())):
	matrix = {'A': [0, 0, 0, 0], 'B': [0, 0, 0, 0], 'C': [0, 0, 0, 0], 'D': [0, 0, 0, 0]}
	for i in range(int(input())):
		mt = input().split()
		if mt[1] == '12':
			matrix[mt[0]][0] += 1
		elif mt[1] == '3':
			matrix[mt[0]][1] += 1
		elif mt[1] == '6':
			matrix[mt[0]][2] += 1
		else:
			matrix[mt[0]][3] += 1
	cp = -400
	for i in range(4):
		for j in range(4):
			if i != j:
				for k in range(4):
					if i != k and j != k:
						for l in range(4):
							if l != i and l != j and (l != k):
								final = [matrix['A'][i], matrix['B'][j], matrix['C'][k], matrix['D'][l]]
								final.sort(reverse=True)
								sum = final[0] * 100 + final[1] * 75 + final[2] * 50 + final[3] * 25 - final.count(0) * 100
								if sum > cp:
									cp = sum
	print(cp)
	tp = tp + cp
print(tp)


t = int(input())
grand_total = 0
while t:
	t -= 1
	n = int(input())
	d = {'A': [0, 0, 0, 0], 'B': [0, 0, 0, 0], 'C': [0, 0, 0, 0], 'D': [0, 0, 0, 0]}
	for i in range(n):
		(movie, time) = input().split()
		time = int(time)
		d[movie][time // 3 - 1] += 1
	ans = -10000
	for i in range(4):
		for j in range(4):
			if i != j:
				for k in range(4):
					if k != j and k != i:
						for l in range(4):
							if l != k and l != j and (l != i):
								arr = [d['A'][i], d['B'][j], d['C'][k], d['D'][l]]
								arr.sort()
								cost = 25
								total = 0
								for z in arr:
									total += cost * z
									cost += 25
								for z in arr:
									if z == 0:
										total -= 100
								if total > ans:
									ans = total
	print(ans)
	grand_total += ans
print(grand_total)


t = input()
temp = {'12': 0, '3': 1, '6': 2, '9': 3}
total = 0
for _ in range(int(t)):
	a = [0, 0, 0, 0]
	b = [0, 0, 0, 0]
	c = [0, 0, 0, 0]
	d = [0, 0, 0, 0]
	n = int(input())
	ans = -400
	if n >= 1:
		for i in range(n):
			s = input().split()
			if s[0] == 'A':
				a[temp[s[1]]] += 1
			elif s[0] == 'B':
				b[temp[s[1]]] += 1
			elif s[0] == 'C':
				c[temp[s[1]]] += 1
			else:
				d[temp[s[1]]] += 1
		for i in range(4):
			for j in range(4):
				for k in range(4):
					for l in range(4):
						temp1 = set([i, j, k, l])
						if len(temp1) == 4:
							prices = [a[i], b[j], c[k], d[l]]
							prices.sort(reverse=True)
							cost = 100 * prices[0] + 75 * prices[1] + 50 * prices[2] + 25 * prices[3]
							cost = cost - 100 * prices.count(0)
							ans = max(ans, cost)
	print(ans)
	total += ans
print(total)


import sys

def getIndex(movie, time):
	i = j = 0
	if movie == 'A':
		i = 0
	elif movie == 'B':
		i = 1
	elif movie == 'C':
		i = 2
	elif movie == 'D':
		i = 3
	if time == '12':
		j = 0
	elif time == '3':
		j = 1
	elif time == '6':
		j = 2
	elif time == '9':
		j = 3
	return (i, j)
result = 0
for _ in range(int(sys.stdin.readline())):
	N = int(sys.stdin.readline())
	total = i = j = 0
	shows = [[0] * 4 for i in range(4)]
	for k in range(N):
		(movie, time) = sys.stdin.readline().strip().split(' ')
		(i, j) = getIndex(movie, time)
		shows[i][j] += 1
	collection = [100, 75, 50, 25]
	ptr = 0
	maximum = -1000000000000
	for i1 in range(4):
		for i2 in range(4):
			if i1 != i2:
				for i3 in range(4):
					if i2 != i3 and i3 != i1:
						for i4 in range(4):
							if i3 != i4 and i2 != i4 and (i4 != i1):
								tempList = [shows[0][i1], shows[1][i2], shows[2][i3], shows[3][i4]]
								tempList.sort(reverse=True)
								tempmaximum = 100 * tempList[0] + 75 * tempList[1] + 50 * tempList[2] + 25 * tempList[3]
								count = tempList.count(0)
								tempmaximum -= count * 100
								if maximum < tempmaximum:
									maximum = tempmaximum
	print(maximum)
	result += maximum
print(result)


s = []

def new(matrix):
	e = []
	for i in range(4):
		for j in range(4):
			for k in range(4):
				for m in range(4):
					if len(set([i, j, k, m])) == 4:
						m = sortedmaxsum([matrix[0][i], matrix[1][j], matrix[2][k], matrix[3][m]])
						e.append(m)
	return int(max(e))

def sortedmaxsum(li):
	li.sort()
	x = 0
	for i in range(4):
		x += li[i] * 25 * (i + 1) if li[i] > 0 else -100
	return x
for _ in range(int(input())):
	ar = []
	r = s1 = f2 = 0
	c = n = 0
	l = []
	n = int(input())
	for i in range(4):
		r = [0] * 4
		ar.append(r)
	for i in range(n):
		(m, t) = input().split()
		t = int(t)
		if m == 'A':
			r = 0
		if t == 12:
			c = 0
		if m == 'B':
			r = 1
		if t == 3:
			c = 1
		if m == 'C':
			r = 2
		if t == 6:
			c = 2
		if m == 'D':
			r = 3
		if t == 9:
			c = 3
		ar[r][c] += 1
	s1 = new(ar)
	s.append(s1)
	print(s1)
print(sum(s))


def func(l, test, mv):
	if len(test) < 4:
		for i in range(4):
			if i not in test:
				test.append(i)
				v = func(l, test, mv)
				if v > mv:
					mv = v
				test.pop()
		return mv
	else:
		v = 0
		temp = []
		for i in range(4):
			temp.append(l[i][test[i]])
		temp.sort()
		pr = [25, 50, 75, 100]
		for i in range(3, -1, -1):
			if temp[i] == 0:
				v -= 100
			else:
				v += temp[i] * pr[i]
		return v
t = int(input())
total = 0
for i in range(t):
	n = int(input())
	l = []
	for k in range(4):
		l.append([0, 0, 0, 0])
	for j in range(n):
		(mve, st) = map(str, input().split())
		st = int(st)
		if mve == 'A':
			if st == 12:
				l[0][0] += 1
			elif st == 3:
				l[0][1] += 1
			elif st == 6:
				l[0][2] += 1
			elif st == 9:
				l[0][3] += 1
		elif mve == 'B':
			if st == 12:
				l[1][0] += 1
			elif st == 3:
				l[1][1] += 1
			elif st == 6:
				l[1][2] += 1
			elif st == 9:
				l[1][3] += 1
		elif mve == 'C':
			if st == 12:
				l[2][0] += 1
			elif st == 3:
				l[2][1] += 1
			elif st == 6:
				l[2][2] += 1
			elif st == 9:
				l[2][3] += 1
		elif mve == 'D':
			if st == 12:
				l[3][0] += 1
			elif st == 3:
				l[3][1] += 1
			elif st == 6:
				l[3][2] += 1
			elif st == 9:
				l[3][3] += 1
	mv = func(l, [], -999999999)
	print(mv)
	total += mv
print(total)


import sys
import itertools

def read_line():
	return sys.stdin.readline().split()
try:
	s = 0
	t = int(read_line()[0])
	for _ in range(t):
		n = int(read_line()[0])
		q = {}
		for i in range(n):
			(a, b) = read_line()
			if q.get((a, b)) == None:
				q[a, b] = 1
			else:
				q[a, b] += 1
		best = -10 ** 18
		for p in itertools.permutations(['A', 'B', 'C', 'D']):
			cost = 0
			li = []
			for (a1, b1) in zip(['12', '3', '6', '9'], p):
				li.append(q.get((b1, a1), 0))
				if li[-1] == 0:
					cost -= 100
			li = sorted(li)
			t2 = 25
			for i in li:
				cost += t2 * i
				t2 += 25
			best = max(best, cost)
		print(best)
		s += best
	print(s)
except:
	pass


t = int(input())
t1 = 0
for i in range(t):
	n = int(input())
	a12 = 0
	a3 = 0
	a6 = 0
	a9 = 0
	b12 = 0
	b3 = 0
	b6 = 0
	b9 = 0
	c12 = 0
	c3 = 0
	c6 = 0
	c9 = 0
	d12 = 0
	d3 = 0
	d6 = 0
	d9 = 0
	for j in range(n):
		s = input()
		if s == 'A 12':
			a12 += 1
		elif s == 'A 3':
			a3 += 1
		elif s == 'A 6':
			a6 += 1
		elif s == 'A 9':
			a9 += 1
		elif s == 'B 12':
			b12 += 1
		elif s == 'B 3':
			b3 += 1
		elif s == 'B 6':
			b6 += 1
		elif s == 'B 9':
			b9 += 1
		elif s == 'C 12':
			c12 += 1
		elif s == 'C 3':
			c3 += 1
		elif s == 'C 6':
			c6 += 1
		elif s == 'C 9':
			c9 += 1
		elif s == 'D 12':
			d12 += 1
		elif s == 'D 3':
			d3 += 1
		elif s == 'D 6':
			d6 += 1
		elif s == 'D 9':
			d9 += 1
	a = [a12, a3, a6, a9, b12, b3, b6, b9, c12, c3, c6, c9, d12, d3, d6, d9]
	d = []
	s1 = 0
	b = [a[0], a[5], a[10], a[15]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[0], a[5], a[11], a[14]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[0], a[6], a[9], a[15]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[0], a[6], a[13], a[11]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[0], a[7], a[9], a[14]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[0], a[7], a[13], a[10]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[1], a[4], a[10], a[15]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[1], a[4], a[14], a[11]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[1], a[6], a[8], a[15]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[1], a[6], a[12], a[11]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[1], a[7], a[8], a[14]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[1], a[7], a[12], a[10]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[2], a[4], a[9], a[15]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[2], a[4], a[13], a[11]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[2], a[5], a[8], a[15]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[2], a[5], a[12], a[11]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[2], a[7], a[9], a[12]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[2], a[7], a[13], a[8]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[3], a[4], a[9], a[14]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[3], a[4], a[13], a[10]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[3], a[5], a[10], a[12]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[3], a[5], a[14], a[8]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[3], a[6], a[8], a[13]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	s1 = 0
	b = [a[3], a[6], a[12], a[9]]
	b.sort()
	s1 = s1 + b[0] * 25 + b[1] * 50 + b[2] * 75 + b[3] * 100
	c = b.count(0)
	s1 = s1 - c * 100
	d.append(s1)
	print(max(d))
	t1 += max(d)
print(t1)


import sys
import itertools

def read_line():
	return sys.stdin.readline().split()
s = 0
T = int(read_line()[0])
for i in range(T):
	n = int(read_line()[0])
	cnt = {}
	for j in range(n):
		(a, b) = read_line()
		if cnt.get((a, b)) == None:
			cnt[a, b] = 1
		else:
			cnt[a, b] += 1
	best = -10 ** 18
	for p in list(itertools.permutations(['A', 'B', 'C', 'D'])):
		cand = 0
		li = []
		for (t, f) in zip(['12', '3', '6', '9'], p):
			li.append(cnt.get((f, t), 0))
			if li[-1] == 0:
				cand -= 100
		li = sorted(li)
		pr = 25
		for x in li:
			cand += pr * x
			pr += 25
		best = max(best, cand)
	print(best)
	s += best
print(s)


main = 0
t = int(input())
for iter in range(t):
	B = {12: 0, 3: 0, 6: 0, 9: 0}
	A = {12: 0, 3: 0, 6: 0, 9: 0}
	C = {12: 0, 3: 0, 6: 0, 9: 0}
	D = {12: 0, 3: 0, 6: 0, 9: 0}
	n = int(input())
	for i in range(n):
		(a, b) = [x for x in input().split()]
		b = int(b)
		if a == 'A':
			A[b] += 1
		if a == 'B':
			B[b] += 1
		if a == 'C':
			C[b] += 1
		if a == 'D':
			D[b] += 1
	max = -100000000
	for i in [12, 3, 6, 9]:
		for j in [12, 3, 6, 9]:
			if j != i:
				for k in [12, 3, 6, 9]:
					if k != j and k != i:
						for l in [12, 3, 6, 9]:
							if l != i and l != j and (l != k):
								li = [A[i], B[j], C[k], D[l]]
								li.sort()
								ans = 0
								ans += 100 * li[3] + 75 * li[2] + 50 * li[1] + 25 * li[0]
								if A[i] == 0:
									ans -= 100
								if B[j] == 0:
									ans -= 100
								if C[k] == 0:
									ans -= 100
								if D[l] == 0:
									ans -= 100
								if ans > max:
									max = ans
	main += max
	print(max)
print(main)


def initialise_empty(graph):
	graph[0] = {'A': 0, 'B': 0, 'C': 0, 'D': 0}
	graph[1] = {'A': 0, 'B': 0, 'C': 0, 'D': 0}
	graph[2] = {'A': 0, 'B': 0, 'C': 0, 'D': 0}
	graph[3] = {'A': 0, 'B': 0, 'C': 0, 'D': 0}
	return graph

def insert_in_list(list_of_list, movie, demand, index):
	list_of_list[index][movie] = list_of_list[index][movie] + demand

def find_sum(value1, value2, value3, value4):
	sum = 0
	temp = []
	temp.append(value1)
	temp.append(value2)
	temp.append(value3)
	temp.append(value4)
	temp.sort(reverse=True)
	if temp[0] == 0:
		sum += -100
	if temp[1] == 0:
		sum += -100
	if temp[2] == 0:
		sum += -100
	if temp[3] == 0:
		sum += -100
	return temp[0] * 100 + temp[1] * 75 + temp[2] * 50 + temp[3] * 25 + sum
mapping = {0: 'A', 1: 'B', 2: 'C', 3: 'D'}
a = int(input())
total = 0
for _ in range(0, a):
	n = int(input())
	graph = [{}] * 4
	graph = initialise_empty(graph)
	for __ in range(0, n):
		(x, y) = input().split()
		x = str(x)
		y = int(y)
		if y == 12:
			insert_in_list(graph, x, y - 11, 0)
		elif y == 3:
			insert_in_list(graph, x, y - 2, 1)
		elif y == 6:
			insert_in_list(graph, x, y - 5, 2)
		elif y == 9:
			insert_in_list(graph, x, y - 8, 3)
	ans = -10000000000000000
	for index in range(0, 4):
		value1 = graph[0][mapping[index]]
		for index2 in range(0, 4):
			value2 = graph[1][mapping[index2]]
			for index3 in range(0, 4):
				value3 = graph[2][mapping[index3]]
				for index4 in range(0, 4):
					value4 = graph[3][mapping[index4]]
					if index in {index2, index3, index4} or index2 in {index3, index4} or index3 in {index4}:
						continue
					else:
						ans = max(ans, find_sum(value1, value2, value3, value4))
	print(ans)
	total = total + ans
print(total)


netsum = 0
from itertools import permutations as per
for _ in range(int(input())):
	dic = {}
	n = input()
	for _ in range(int(n)):
		(a, b) = input().split()
		if (a, b) not in dic:
			dic[a, b] = 1
		else:
			dic[a, b] += 1
	price = -10 ** 3
	for p in list(per(['A', 'B', 'C', 'D'])):
		profit = 0
		l = []
		for k in zip(p, ['12', '3', '6', '9']):
			l.append(dic.get(k, 0))
			if l[-1] == 0:
				profit -= 100
		l = sorted(l)
		pr = 25
		for i in l:
			profit += pr * i
			pr += 25
		price = max(price, profit)
	print(price)
	netsum += price
print(netsum)


t = int(input())
SUM = 0
while t:
	a = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
	n = int(input())
	for i in range(n):
		s = input().split()
		if s[0] == 'A':
			if s[1] == '12':
				a[0][0] += 1
			elif s[1] == '3':
				a[0][1] += 1
			elif s[1] == '6':
				a[0][2] += 1
			else:
				a[0][3] += 1
		elif s[0] == 'B':
			if s[1] == '12':
				a[1][0] += 1
			elif s[1] == '3':
				a[1][1] += 1
			elif s[1] == '6':
				a[1][2] += 1
			else:
				a[1][3] += 1
		elif s[0] == 'C':
			if s[1] == '12':
				a[2][0] += 1
			elif s[1] == '3':
				a[2][1] += 1
			elif s[1] == '6':
				a[2][2] += 1
			else:
				a[2][3] += 1
		elif s[1] == '12':
			a[3][0] += 1
		elif s[1] == '3':
			a[3][1] += 1
		elif s[1] == '6':
			a[3][2] += 1
		else:
			a[3][3] += 1
	s = 0
	x = [100, 75, 50, 25]
	max = -400
	for i in range(0, 4):
		s = 0
		d = []
		d.append(a[0][i])
		b = []
		b.append(i)
		for j in range(0, 4):
			if j not in b:
				d.append(a[1][j])
				b.append(j)
				for k in range(0, 4):
					if k not in b:
						d.append(a[2][k])
						b.append(k)
						for l in range(0, 4):
							if l not in b:
								d.append(a[3][l])
								g = d[:]
								d.sort()
								s = 0
								q = 0
								for h in range(3, -1, -1):
									if d[h] == 0:
										s -= 100
									else:
										s += d[h] * x[q]
										q += 1
								if s > max:
									max = s
								d = g[:3]
						b = b[:2]
						d = d[:2]
				b = b[:1]
				d = d[:1]
		d = []
		b = []
	print(max)
	SUM += max
	t -= 1
print(SUM)


from itertools import permutations
total = 0
t = int(input())
for i in range(t):
	da = [x for x in range(4)]
	comb = list(permutations(da))
	index_map = {12: 0, 3: 1, 6: 2, 9: 3}
	data = {}
	data['A'] = [0, 0, 0, 0]
	data['B'] = [0, 0, 0, 0]
	data['C'] = [0, 0, 0, 0]
	data['D'] = [0, 0, 0, 0]
	n = int(input())
	for j in range(n):
		(m, t) = input().split()
		t = int(t)
		data[m][index_map[t]] += 1
	profit = -400
	for h in comb:
		ans = []
		for h1 in range(4):
			charac = chr(h[h1] + 65)
			ans.append(data[charac][h1])
		ans.sort(reverse=True)
		temp = 0
		price = 100
		for b in range(4):
			if ans[b] == 0:
				temp = temp - 100
			else:
				temp = temp + ans[b] * price
				price = price - 25
		if temp > profit:
			profit = temp
	print(profit)
	total += profit
print(total)


def calc(nex):
	final = nex.copy()
	final.sort()
	final = final[::-1]
	price = [100, 75, 50, 25]
	tot = 0
	for i in range(0, len(final)):
		tot = tot + price[i] * final[i]
		if final[i] == 0:
			tot = tot - 100
	return tot
t = int(input())
sums = 0
for _ in range(0, t):
	n = int(input())
	key = {'A': 0, 'B': 1, 'C': 2, 'D': 3}
	revkey = ['A', 'B', 'C', 'D']
	k2 = {12: 0, 3: 1, 6: 2, 9: 3}
	k3 = [12, 3, 6, 9]
	k4 = ['A', 'B', 'C', 'D']
	done = {'A': 0, 'B': 0, 'C': 0, 'D': 0}
	arr = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
	for _ in range(0, n):
		(x, y) = input().split()
		arr[key[x]][k2[int(y)]] = arr[key[x]][k2[int(y)]] + 1
	result = -500
	temp = 0
	for a in range(4):
		final = []
		final.append(arr[0][a])
		for b in range(4):
			if a != b:
				final.append(arr[1][b])
				for c in range(4):
					if c != a and c != b:
						final.append(arr[2][c])
						for d in range(4):
							if d != a and d != b and (d != c):
								final.append(arr[3][d])
								temp = calc(final)
								result = result < temp and temp or result
								final.pop()
						final.pop()
				final.pop()
	print(result)
	sums = sums + result
print(sums)


rows = [(0, 1, 2, 3), (0, 1, 3, 2), (0, 2, 1, 3), (0, 2, 3, 1), (0, 3, 1, 2), (0, 3, 2, 1), (1, 0, 2, 3), (1, 0, 3, 2), (1, 2, 0, 3), (1, 2, 3, 0), (1, 3, 0, 2), (1, 3, 2, 0), (2, 0, 1, 3), (2, 0, 3, 1), (2, 1, 0, 3), (2, 1, 3, 0), (2, 3, 0, 1), (2, 3, 1, 0), (3, 0, 1, 2), (3, 0, 2, 1), (3, 1, 0, 2), (3, 1, 2, 0), (3, 2, 0, 1), (3, 2, 1, 0)]
answer = []
for __ in range(int(input())):
	matrix = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
	for __ in range(int(input())):
		(show, timing) = (num if not num.isdigit() else int(num) for num in input().split())
		if show == 'A':
			matrix[0][timing // 3 - 1] += 1
		elif show == 'B':
			matrix[1][timing // 3 - 1] += 1
		elif show == 'C':
			matrix[2][timing // 3 - 1] += 1
		elif show == 'D':
			matrix[3][timing // 3 - 1] += 1
	columns = [0, 1, 2, 3]
	cost = None
	show_chosen = []
	for row in rows:
		temp_show = []
		for (ind, i) in enumerate(list(zip(row, (0, 1, 2, 3)))):
			temp_show.append(matrix[i[0]][i[1]])
		show_chosen.append(temp_show)
	for show_ in show_chosen:
		count = 0
		temp_cost = 0
		for y in sorted(show_, reverse=True):
			if y == 0:
				temp_cost -= 100
			else:
				temp_cost += y * (25 * (4 - count))
				count += 1
		if cost is None:
			cost = temp_cost
		elif cost < temp_cost:
			cost = temp_cost
	answer.append(cost)
for output in answer:
	print(output)
print(sum(answer))


from itertools import permutations
perms = [i for i in permutations([0, 1, 2, 3]) if len(set(i)) == 4]
final = []
m = {'A': 0, 'B': 1, 'C': 2, 'D': 3}
t = {'12': 0, '3': 1, '6': 2, '9': 3}
for i in range(int(input())):
	arr = [[0] * 4 for i in range(4)]
	for i in range(int(input())):
		(c, n) = map(str, input().split(' '))
		arr[m[c]][t[n]] += 1
	container = []
	for movie in perms:
		for time in perms:
			money = []
			profit = [100, 75, 50, 25]
			for (i, j) in zip(movie, time):
				money.append(arr[i][j])
				money.sort(reverse=True)
			mo = 0
			for (i, j) in zip(money, profit):
				if i > 0:
					mo += i * j
				else:
					mo -= 100
			container.append(mo)
	s = max(container)
	print(s)
	final.append(s)
print(sum(final))


import itertools
a = ['A', 'B', 'C', 'D']
b = ['3', '12', '6', '9']
combi = list(itertools.permutations(b, 4))
s = []
for i in combi:
	lol = []
	for j in range(4):
		lol.append(a[j] + i[j])
	s.append(lol[:])
dd = []
for _ in range(int(input())):
	n = int(input())
	d = dict()
	for i in s:
		for j in i:
			d[j] = 0
	for i in range(n):
		(o, p) = input().split()
		d[o + p] += 1
	ans = []
	for i in s:
		lol = []
		for j in i:
			lol.append(d[j])
		lol.sort()
		curr = 25
		ca = 0
		for j in lol:
			if j == 0:
				ca -= 100
			else:
				ca += curr * j
			curr += 25
		ans.append(ca)
	print(max(ans))
	dd.append(max(ans))
print(sum(dd))