#include #define rep(i,a,b) for(int i = (a); i < (b); i++) #define all(A) (A).begin(),(A).end() #define MOD 1000000007 using namespace std; using ll = long long; using Graph = vector>; int main(void){ int n,m; cin >> n >> m; map R; rep(i,0,n+m){ string name; cin >> name; int r; cin >> r; R[name] = r; } for(auto& [k,v] : R) cout << k << " " << v << endl; }