#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<climits>
#include<numeric>
#include<set>
#include<sstream>
#include<map>
#include<vector>
#include<string>
#include<regex>

using namespace std;

const long long MOD = (long long)(1e9 + 7);

vector<string> split(const string& haystack, const string& needle) {
	vector<string> result;
	size_t start_pos = 0;
	size_t found_pos = haystack.find(needle, start_pos);
	while (found_pos != string::npos) {
		size_t count = found_pos - start_pos;
		string token = haystack.substr(start_pos, count);
		if (!token.empty()) {
			result.push_back(token);
		}
		start_pos = found_pos + needle.length();
		found_pos = haystack.find(needle, start_pos);
	}

	string last_token = haystack.substr(start_pos);
	if (!last_token.empty()) {
		result.push_back(last_token);
	}
	return result;
}

int main() {
	string line;
	map<string, int> goals;
	while (getline(cin, line)) {
		auto parts = split(line, " - ");

		int lastSpace = parts[0].find_last_of(" ");
		string team_one = parts[0].substr(0, lastSpace);
		int grade_one = stoi(parts[0].substr(lastSpace + 1));

		int firstSpace = parts[1].find_first_of(" ");
		string team_two = parts[1].substr(firstSpace + 1);
		int grade_two = stoi(parts[1].substr(0, firstSpace));

		goals[team_one] += grade_one;
		goals[team_two] += grade_two;
	}

	vector<pair<string, int>> teams{ goals.begin(),goals.end() };
	sort(teams.begin(), teams.end(), [](const auto& a, const auto& b) {
		return a.second != b.second ? a.second > b.second:a.first < b.first;
	});
	for (auto entry : teams) {
		cout << entry.first << " " << entry.second << endl;
	}
	/*for (const auto& [team, score] : teams) {
		cout << team << " " << score << endl;
	}*/
	return 0;
}

