#include using namespace std; int main(void) { int n, m; cin >> n >> m; map s; map t; for (int i = 1; i <= n; i++) { string s_tmp; int a_tmp; cin >> s_tmp >> a_tmp; s[s_tmp] = a_tmp; } for (int i = 1; i <= m; i++) { string s_tmp; int a_tmp; cin >> s_tmp >> a_tmp; s[s_tmp] = a_tmp; } for (auto itr = s.begin(); itr != s.end(); itr++) { cout << itr->first << " " << itr->second << endl; } return 0; }