local n, m = io.read("*n", "*n", "*l") local t = {} for i = 1, n + m do local s, a = io.read():match("(%g+) (%d+)") t[s] = a end local z = {} for k, v in pairs(t) do table.insert(z, {k, v}) end table.sort(z, function(a, b) return a[1] < b[1] end) for i = 1, #z do print(z[i][1] .. " " .. z[i][2]) end