#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool Compare(pair<int, pair<int, string>> a, pair<int, pair<int, string>> b)
{
if (a.first == b.first)
{
return a.second.first < b.second.first;
}
else
{
return a.first < b.first;
}
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<pair<int, pair<int, string>>> in;
int input = 0;
cin >> input;
for (int i = 0; i < input; ++i)
{
pair<int, pair<int, string>> a;
cin >> a.first >> a.second.second;
a.second.first = i;
in.push_back(a);
}
sort(in.begin(), in.end(), Compare);
for (vector<pair<int, pair<int, string>>>::iterator iter = in.begin(); iter != in.end(); ++iter)
{
cout << (*iter).first << " " << (*iter).second.second << "\n";
}
return 0;
}
코딩 테스트