#include <iostream>
#include <cstdio>

using namespace std;

typedef struct {
	int num;
	int score;
} CHECK;

int main()
{
	CHECK check[100], tmp;
	int cnt = 0;

	while (1){
		scanf("%d,%d", &check[cnt].num, &check[cnt].score);

		if (check[cnt].num == 0 && check[cnt].score == 0){
			break;
		}
		cnt++;
	}

	for (int i = 0; i < cnt; i++){
		for (int j = cnt - 1; j > 0; j--){
			if (check[j].score > check[j - 1].score){
				tmp = check[j - 1];
				check[j - 1] = check[j];
				check[j] = tmp;
			}
		}
	}

	for (int i = 0; i < cnt; i++){
		cout << check[i].num << endl;
	}

	return (0);
}