using System; namespace No750_Frac_1 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] a = new int[n]; int[] b = new int[n]; string[] data = new string[2]; int[] value = new int[n]; int[] rank = new int[n]; int lcm; for (int i = 0; i < n; i++) { data = Console.ReadLine().Split(' '); a[i] = int.Parse(data[0]); b[i] = int.Parse(data[1]); rank[i] = i; } if (n > 2) { lcm = Lcm(b); for (int i = 0; i < n; i++) value[i] = a[i] * lcm / b[i]; Sort(value, ref rank); } for (int i = 0; i < n; i++) Console.WriteLine(a[rank[i]] + " " + b[rank[i]]); } static void Sort(int[] value, ref int[] rank) { int n = value.Length; for (int i = 0; i < n - 1; i++) { for (int j = i; j < n; j++) { if (value[i] < value[j]) { Swap(ref value[i], ref value[j]); Swap(ref rank[i], ref rank[j]); } } } } static int Lcm(int[] num) { int result = Lcm(num[0], num[1]); for (int i = 2; i < num.Length - 1; i++) { result = Lcm(result, num[i]); } return result; } static int Lcm(int a, int b) { return a * b / Gcd(a, b); } static int Gcd(int a, int b) { if (a < b) Swap(ref a, ref b); while (b != 0) { int rem = a % b; a = b; b = rem; } return a; } static void Swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } } }