#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(a) (a).begin(),(a).end() //lower_bound(ALL(a),x) using ll = long long; using P = pair; using VI = vector; using VVI = vector>; template bool chmax(T &a, const T& b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template bool chmin(T &a, const T& b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } int INF = 100100100; int main() { int n,m; cin >> n >> m; map rating; rep(i,n) { string name; int r; cin >> name >> r; rating[name] = r; } rep(i,m) { string name; int nr; cin >> name >> nr; rating[name] = nr; } vector ret; for (auto i = rating.begin(); i != rating.end(); i++) { ret.push_back(i -> first); } sort(ALL(ret)); for (auto ans: ret) { cout << ans << " " << rating[ans] << endl; } }