#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Student
{
public:
Student(string _name, int _score) {
name = _name;
score = _score;
}
bool operator < (const Student student)const {
return score < student.score;
}
string name;
int score;
};
int main()
{
int n,m;
cin>>n>>m;
vector <Student> myStudent;
for(int it=0; it<n; it++) {
string name;
int score;
cin >> name >> score;
Student temp(name, score);
myStudent.push_back(temp);
}
sort(myStudent.begin(), myStudent.begin()+n);
while(m--) {
int num;
cin>>num;
cout<<myStudent[num-1].name<<" "<<myStudent[num-1].score<<endl;
}
}