let input = require('fs').readFileSync('/dev/stdin', 'utf8'); input = input.split('\n') input.shift(); input.pop(); let AB = input .map(v => v .split(/\s/) .map(v => Number(v))) .map(v => [v[0], v[1], v[0] / v[1]]) .sort((a, b) => b[2] - a[2]); console.log(AB .map(v => `${v[0]} ${v[1]}`) .join`\n`);