#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; int N, M; map A, ans; int main() { cin >> N >> M; for (int i = 0; i < N; i++) { string s; int a; cin >> s >> a; A[s] = a; } for (int i = 0; i < M; i++) { string s; int a; cin >> s >> a; A[s] = a; } for (auto p: A) { cout << p.first << ' ' << p.second << endl; } return 0; }