#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; template constexpr int lcm(array a) { T res = 1; for (int i = 0; i < a.size(); ++i) { res = lcm(res, a[i]); } return res; } int main() { constexpr int LCM = lcm({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }); int n; cin >> n; vector> res; rep(i, n) { int a, b; cin >> a >> b; res.push_back({ a, b, a * LCM / b }); } sort(res.begin(), res.end(), [](auto a, auto b) { return get<2>(a) > get<2>(b); }); for (auto [a, b, c] : res) { cout << a << " " << b << endl; } return 0; }