#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;


int main()
{
    multimap<int, int, greater<int> > r;
    int n, m;
    char comma;
    while(cin >> n >> comma >> m && n && m)
    {
        r.insert(multimap<int, int, greater<int> >::value_type(m, n));
    }
    multimap<int, int, greater<int> >::iterator it = r.begin();
    while(it != r.end())
    {
        cout << (*it).second << endl;
        ++it;
    }
}