fun main() { val builder = StringBuilder() val n = readInputLine().toInt() repeat(n) { var (a, b) = readInputLine().split(" ").map { it.toLong() } val ans = mutableListOf() val ansRev = mutableListOf() while (a != b) { val gcd = gcd(a, b) if ((a / gcd) % 2L == 1L) { ans.add(gcd) a += gcd } else { ansRev.add(gcd) b -= gcd } } builder.appendln(ans.size + ansRev.size) if (ans.isNotEmpty()) { builder.append(ans.joinToString(" ") + " ") } builder.appendln(ansRev.reversed().joinToString(" ")) } print(builder.toString()) } fun readInputLine(): String { return readLine()!! } tailrec fun gcd(a: Long, b: Long): Long = when { b > a -> gcd(b, a) b == 0L -> a else -> gcd(b, a % b) }