import java.io.*
import java.util.*

class FastWriter(outputStream: PrintStream = System.out) {
    private val writer = PrintWriter(outputStream)
    fun close() = writer.close()
    fun println(i: Int) = writer.println(i)
    fun println(s: String) = writer.println(s)

    companion object {
        fun create(): FastWriter = FastWriter()
    }
}

class FastReader(private val stream: InputStream = System.`in`) {
    private val buf = ByteArray(1024)
    private var curChar: Int = 0
    private var numChars: Int = 0
    fun readIntArrays(vararg arrays: IntArray) {
        for (i in arrays[0].indices) {
            for (j in arrays.indices) {
                arrays[j][i] = readInt()
            }
        }
    }

    fun readInt(): Int {
        var c = read()
        while (isSpaceChar(c)) {
            c = read()
        }
        var sgn = 1
        if (c == '-'.toInt()) {
            sgn = -1
            c = read()
        }
        var res = 0
        do {
            if (c < '0'.toInt() || c > '9'.toInt()) {
                throw InputMismatchException()
            }
            res *= 10
            res += c - '0'.toInt()
            c = read()
        } while (!isSpaceChar(c))
        return res * sgn
    }

    fun readString(): String {
        var c = read()
        while (isSpaceChar(c)) {
            c = read()
        }
        val res = StringBuilder()
        do {
            if (Character.isValidCodePoint(c)) {
                res.appendCodePoint(c)
            }
            c = read()
        } while (!isSpaceChar(c))
        return res.toString()
    }

    operator fun next(): String = readString()
    private fun read(): Int {
        if (numChars == -1) {
            throw InputMismatchException()
        }
        if (curChar >= numChars) {
            curChar = 0
            try {
                numChars = stream.read(buf)
            } catch (e: IOException) {
                throw InputMismatchException()
            }

            if (numChars <= 0) {
                return -1
            }
        }
        return buf[curChar++].toInt()
    }

    private fun isSpaceChar(c: Int): Boolean =
        c == ' '.toInt() || c == '\n'.toInt() || c == '\r'.toInt() || c == '\t'.toInt() || c == -1
}

fun main() {
    val input = FastReader()
    val output = FastWriter()
    repeat(input.readInt()) {
        val a = input.readInt()
        when {
            a < 1000 -> {
                output.println(a)
            }
            a < 999500 -> {
                output.println("${(a + 500) / 1000}K")
            }
            else -> {
                output.println("${(a + 500000) / 1000000}M")
            }
        }
    }
}


private fun readString() = readLine()!!
private fun readInt() = readString().toInt()

fun main() {
    repeat(readInt()) {
        f()
    }
}

fun f() {
    val a = readInt()
    when {
        a < 1000 -> {
            println(a)
        }
        a < 999500 -> {
            println("${(a + 500) / 1000}K")
        }
        else -> {
            println("${(a + 500000) / 1000000}M")
        }
    }
}


package org.example

import java.io.IOException
import java.io.InputStream
import java.io.PrintStream
import java.io.PrintWriter
import java.util.*

object progremkt {
    internal  class FastWriter(outputStream: PrintStream = System.out) {
        private val writer = PrintWriter(outputStream)
        fun close() = writer.close()
        fun println(i: Int) = writer.println(i)
        fun println(s: String) = writer.println(s)

        companion object {
            fun create(): FastWriter = FastWriter()
        }
    }

    internal class FastReader(private val stream: InputStream = System.`in`) {
        private val buf = ByteArray(1024)
        private var curChar: Int = 0
        private var numChars: Int = 0
        fun readIntArrays(vararg arrays: IntArray) {
            for (i in arrays[0].indices) {
                for (j in arrays.indices) {
                    arrays[j][i] = readInt()
                }
            }
        }

        fun readInt(): Int {
            var c = read()
            while (isSpaceChar(c)) {
                c = read()
            }
            var sgn = 1
            if (c == '-'.toInt()) {
                sgn = -1
                c = read()
            }
            var res = 0
            do {
                if (c < '0'.toInt() || c > '9'.toInt()) {
                    throw InputMismatchException()
                }
                res *= 10
                res += c - '0'.toInt()
                c = read()
            } while (!isSpaceChar(c))
            return res * sgn
        }

        fun readString(): String {
            var c = read()
            while (isSpaceChar(c)) {
                c = read()
            }
            val res = StringBuilder()
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c)
                }
                c = read()
            } while (!isSpaceChar(c))
            return res.toString()
        }

        operator fun next(): String = readString()
        private fun read(): Int {
            if (numChars == -1) {
                throw InputMismatchException()
            }
            if (curChar >= numChars) {
                curChar = 0
                try {
                    numChars = stream.read(buf)
                } catch (e: IOException) {
                    throw InputMismatchException()
                }

                if (numChars <= 0) {
                    return -1
                }
            }
            return buf[curChar++].toInt()
        }

        private fun isSpaceChar(c: Int): Boolean =
            c == ' '.toInt() || c == '\n'.toInt() || c == '\r'.toInt() || c == '\t'.toInt() || c == -1
    }

    private fun f(inputReader: FastReader, outputWriter: FastWriter) {
        val a = inputReader.readInt()
        when {
            a < 1000 -> {
                outputWriter.println(a)
            }
            a < 999500 -> {
                outputWriter.println("${(a + 500) / 1000}K")
            }
            else -> {
                outputWriter.println("${(a + 500000) / 1000000}M")
            }
        }
    }

    @JvmStatic
    fun main() {
        val input = FastReader()
        val output = FastWriter()
        repeat(input.readInt()) {
            f(input, output)
        }
    }
}


import java.io.IOException
import java.io.InputStream
import java.io.PrintStream
import java.io.PrintWriter
import java.util.*

internal class FastWriter(outputStream: PrintStream = System.out) {
    private val writer = PrintWriter(outputStream)
    fun close() = writer.close()
    fun println(i: Int) = writer.println(i)
    fun println(s: String) = writer.println(s)

    companion object {
        fun create(): FastWriter = FastWriter()
    }
}

internal class FastReader(private val stream: InputStream = System.`in`) {
    private val buf = ByteArray(1024)
    private var curChar: Int = 0
    private var numChars: Int = 0
    fun readIntArrays(vararg arrays: IntArray) {
        for (i in arrays[0].indices) {
            for (j in arrays.indices) {
                arrays[j][i] = readInt()
            }
        }
    }

    fun readInt(): Int {
        var c = read()
        while (isSpaceChar(c)) {
            c = read()
        }
        var sgn = 1
        if (c == '-'.toInt()) {
            sgn = -1
            c = read()
        }
        var res = 0
        do {
            if (c < '0'.toInt() || c > '9'.toInt()) {
                throw InputMismatchException()
            }
            res *= 10
            res += c - '0'.toInt()
            c = read()
        } while (!isSpaceChar(c))
        return res * sgn
    }

    fun readString(): String {
        var c = read()
        while (isSpaceChar(c)) {
            c = read()
        }
        val res = StringBuilder()
        do {
            if (Character.isValidCodePoint(c)) {
                res.appendCodePoint(c)
            }
            c = read()
        } while (!isSpaceChar(c))
        return res.toString()
    }

    operator fun next(): String = readString()
    private fun read(): Int {
        if (numChars == -1) {
            throw InputMismatchException()
        }
        if (curChar >= numChars) {
            curChar = 0
            try {
                numChars = stream.read(buf)
            } catch (e: IOException) {
                throw InputMismatchException()
            }

            if (numChars <= 0) {
                return -1
            }
        }
        return buf[curChar++].toInt()
    }

    private fun isSpaceChar(c: Int): Boolean =
        c == ' '.toInt() || c == '\n'.toInt() || c == '\r'.toInt() || c == '\t'.toInt() || c == -1
}

private fun f(inputReader: FastReader, outputWriter: FastWriter) {
    val a = inputReader.readInt()
    when {
        a < 1000 -> {
            outputWriter.println(a)
        }
        a < 999500 -> {
            outputWriter.println("${(a + 500) / 1000}K")
        }
        else -> {
            outputWriter.println("${(a + 500000) / 1000000}M")
        }
    }
}

fun main() {
    val input = FastReader()
    val output = FastWriter()
    repeat(input.readInt()) {
        f(input, output)
    }
}


import java.io.*
import java.util.*

object programkt {
    const val BUFFER_SIZE = 1024

    internal class FastWriter(outputStream: OutputStream) {
        private val writer = PrintWriter(BufferedWriter(OutputStreamWriter(outputStream)))
        fun print(vararg objects: Any) {
            for (i in objects.indices) {
                if (i != 0) {
                    writer.print(' ')
                }
                writer.print(objects[i])
            }
        }

        fun printLine(vararg objects: Any) {
            print(*objects)
            writer.println()
        }

        fun close() {
            writer.close()
        }

        fun printLine(i: Int) {
            writer.println(i)
        }
    }

    internal class FastReader(private val stream: InputStream) {
        private val buf = ByteArray(BUFFER_SIZE)
        private var curChar: Int = 0
        private var numChars: Int = 0
        private val filter: FastReader.SpaceCharFilter? = null
        fun read(): Int {
            if (numChars == -1) throw InputMismatchException()

            if (curChar >= numChars) {
                curChar = 0
                try {
                    numChars = stream.read(buf)
                } catch (e: IOException) {
                    throw InputMismatchException()
                }
                if (numChars <= 0) return -1
            }
            return buf[curChar++].toInt()
        }

        fun readInt(): Int {
            var c = read()
            while (isSpaceChar(c)) {
                c = read()
            }
            var sgn = 1
            if (c == '-'.toInt()) {
                sgn = -1
                c = read()
            }
            var res = 0
            do {
                if (c < '0'.toInt() || c > '9'.toInt()) throw InputMismatchException()
                res *= 10
                res += c - '0'.toInt()
                c = read()
            } while (!isSpaceChar(c))
            return res * sgn
        }

        fun readString(): String {
            var c = read()
            while (isSpaceChar(c)) {
                c = read()
            }
            val res = StringBuilder()
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c)
                }
                c = read()
            } while (!isSpaceChar(c))
            return res.toString()
        }

        fun isSpaceChar(c: Int): Boolean = filter?.isSpaceChar(c) ?: isWhitespace(c)
        operator fun next(): String = readString()
        interface SpaceCharFilter {
            fun isSpaceChar(ch: Int): Boolean
        }

        companion object {
            fun isWhitespace(c: Int): Boolean =
                c == ' '.toInt() || c == '\n'.toInt() || c == '\r'.toInt() || c == '\t'.toInt() || c == -1
        }
    }

    @JvmStatic
    fun main() {
        val inputStream = System.`in`
        val outputStream = System.out
        val input = FastReader(inputStream)
        val output = FastWriter(outputStream)
        repeat(input.readInt()) {
            val a = input.readInt()
            when {
                a < 1000 -> {
                    output.printLine(a)
                }
                a < 999500 -> {
                    output.printLine("${(a + 500) / 1000}K")
                }
                else -> {
                    output.printLine("${(a + 500000) / 1000000}M")
                }
            }
        }
    }
}


import java.io.*
import java.util.*

object programkt {
    internal class FastWriter(outputStream: PrintStream = System.out) {
        private val writer = PrintWriter(outputStream)
        fun close() = writer.close()
        fun println(i: Int) = writer.println(i)
        fun println(s: String) = writer.println(s)

        companion object {
            fun create(): FastWriter = FastWriter()
        }
    }

    internal class FastReader(private val stream: InputStream = System.`in`) {
        private val buf = ByteArray(1024)
        private var curChar: Int = 0
        private var numChars: Int = 0
        fun readIntArrays(vararg arrays: IntArray) {
            for (i in arrays[0].indices) {
                for (j in arrays.indices) {
                    arrays[j][i] = readInt()
                }
            }
        }

        fun readInt(): Int {
            var c = read()
            while (isSpaceChar(c)) {
                c = read()
            }
            var sgn = 1
            if (c == '-'.toInt()) {
                sgn = -1
                c = read()
            }
            var res = 0
            do {
                if (c < '0'.toInt() || c > '9'.toInt()) {
                    throw InputMismatchException()
                }
                res *= 10
                res += c - '0'.toInt()
                c = read()
            } while (!isSpaceChar(c))
            return res * sgn
        }

        fun readString(): String {
            var c = read()
            while (isSpaceChar(c)) {
                c = read()
            }
            val res = StringBuilder()
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c)
                }
                c = read()
            } while (!isSpaceChar(c))
            return res.toString()
        }

        operator fun next(): String = readString()
        private fun read(): Int {
            if (numChars == -1) {
                throw InputMismatchException()
            }
            if (curChar >= numChars) {
                curChar = 0
                try {
                    numChars = stream.read(buf)
                } catch (e: IOException) {
                    throw InputMismatchException()
                }

                if (numChars <= 0) {
                    return -1
                }
            }
            return buf[curChar++].toInt()
        }

        private fun isSpaceChar(c: Int): Boolean =
            c == ' '.toInt() || c == '\n'.toInt() || c == '\r'.toInt() || c == '\t'.toInt() || c == -1
    }

    @JvmStatic
    fun main() {
        val input = FastReader()
        val output = FastWriter()
        repeat(input.readInt()) {
            val a = input.readInt()
            when {
                a < 1000 -> {
                    output.println(a)
                }
                a < 999500 -> {
                    output.println("${(a + 500) / 1000}K")
                }
                else -> {
                    output.println("${(a + 500000) / 1000000}M")
                }
            }
        }
    }
}


package org.example

import java.io.IOException
import java.io.InputStream
import java.io.PrintStream
import java.io.PrintWriter
import java.util.*

object programkt {
    internal  class FastWriter(outputStream: PrintStream = System.out) {
        private val writer = PrintWriter(outputStream)
        fun close() = writer.close()
        fun println(i: Int) = writer.println(i)
        fun println(s: String) = writer.println(s)

        companion object {
            fun create(): FastWriter = FastWriter()
        }
    }

    internal class FastReader(private val stream: InputStream = System.`in`) {
        private val buf = ByteArray(1024)
        private var curChar: Int = 0
        private var numChars: Int = 0
        fun readIntArrays(vararg arrays: IntArray) {
            for (i in arrays[0].indices) {
                for (j in arrays.indices) {
                    arrays[j][i] = readInt()
                }
            }
        }

        fun readInt(): Int {
            var c = read()
            while (isSpaceChar(c)) {
                c = read()
            }
            var sgn = 1
            if (c == '-'.toInt()) {
                sgn = -1
                c = read()
            }
            var res = 0
            do {
                if (c < '0'.toInt() || c > '9'.toInt()) {
                    throw InputMismatchException()
                }
                res *= 10
                res += c - '0'.toInt()
                c = read()
            } while (!isSpaceChar(c))
            return res * sgn
        }

        fun readString(): String {
            var c = read()
            while (isSpaceChar(c)) {
                c = read()
            }
            val res = StringBuilder()
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c)
                }
                c = read()
            } while (!isSpaceChar(c))
            return res.toString()
        }

        operator fun next(): String = readString()
        private fun read(): Int {
            if (numChars == -1) {
                throw InputMismatchException()
            }
            if (curChar >= numChars) {
                curChar = 0
                try {
                    numChars = stream.read(buf)
                } catch (e: IOException) {
                    throw InputMismatchException()
                }

                if (numChars <= 0) {
                    return -1
                }
            }
            return buf[curChar++].toInt()
        }

        private fun isSpaceChar(c: Int): Boolean =
            c == ' '.toInt() || c == '\n'.toInt() || c == '\r'.toInt() || c == '\t'.toInt() || c == -1
    }

    private fun f(inputReader: FastReader, outputWriter: FastWriter) {
        val a = inputReader.readInt()
        when {
            a < 1000 -> {
                outputWriter.println(a)
            }
            a < 999500 -> {
                outputWriter.println("${(a + 500) / 1000}K")
            }
            else -> {
                outputWriter.println("${(a + 500000) / 1000000}M")
            }
        }
    }

    @JvmStatic
    fun main() {
        val input = FastReader()
        val output = FastWriter()
        repeat(input.readInt()) {
            f(input, output)
        }
    }
}


import kotlin.math.round

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

fun main(){
    var TC = readInt()
    while(TC!=0){
        var x = readInt()
        if(x <= 999){
            println(x)
            continue
        }
        if(x < 999500){
            var X = x/1000.0;
            var y = round(X)
            print(String.format("%.0f",y))
            println("K")
            continue
        }
        var X = x/1000000.0;
        var y = round(X)
        print(String.format("%.0f",y))
        println("M")
        TC--
    }
}


import kotlin.math.round

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

fun main(){
    var TC = readInt()
    for(tc in 1..TC){
        var x = readInt()
        if(x <= 999){
            println(x)
            continue
        }
        if(x < 999500){
            var X = x/1000.0;
            print(String.format("%.0f",y))
            println("K")
            continue
        }
        var X = x/1000000.0;
        print(String.format("%.0f",y))
        println("M")
    }
}


import kotlin.math.round

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

fun main(){
    var TC = readInt()
    for(tc in 1..TC){
        var x = readInt()
        if(x <= 999){
            println(x)
            continue
        }
        if(x < 999500){
            var X = x/1000.0;
            print(String.format("%.0f",X))
            println("K")
            continue
        }
        var X = x/1000000.0;
        print(String.format("%.0f",X))
        println("M")
    }
}


import kotlin.math.round

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

fun main(){
    var TC = readInt()
    for(tc in 1..TC){
        var x = readInt()
        if(x <= 999){
            println(x)
            continue
        }
        if(x < 999500){
            x++
            var X = x/1000.0;
            var y = round(X)
            print(String.format("%.0f",y))
            println("K")
            continue
        }
        x++
        var X = x/1000000.0;
        var y = round(X)
        print(String.format("%.0f",y))
        println("M")
    }
}


import kotlin.math.round

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

fun main(){
    var TC = readInt()
    for(tc in 1..TC){
        var x = readInt()
        if(x <= 999){
            println(x)
            continue
        }
        if(x < 999500){
            var X = x/1000.0;
            var y = round(X)
            print(String.format("%.0f",y))
            println("K")
            continue
        }
        var X = x/1000000.0;
        var y = round(X)
        print(String.format("%.0f",y))
        println("M")
    }
}


import java.math.BigDecimal
import java.math.RoundingMode

fun readLn() = readLine()!! // string line
fun readInt() = readLn().toInt()

fun main() {
    val t = readInt()

    for (i in 0 until t) {
        val n = readInt()
        println(output(n))
    }
}

fun output(n: Int): String {
    val (divisor, suffix) = when {
        n >= 500_000 -> BigDecimal(1_000_000) to "M"
        n >= 1000 -> BigDecimal(1_000) to "K"
        else -> BigDecimal(1) to ""
    }
    val nDecimal = BigDecimal(n)
    val digits = nDecimal.divide(divisor, RoundingMode.HALF_UP).toInt()

    return "$digits$suffix"
}


import java.math.BigDecimal
import java.math.RoundingMode

fun readLn() = readLine()!! // string line
fun readInt() = readLn().toInt()

fun main() {
    val t = readInt()

    for (i in 0 until t) {
        val n = readInt()
        println(output(n))
    }
}

fun output(n: Int): String {
    val nDecimal = BigDecimal(n)

    val (divisor, suffix) = when {
        n >= 1_000_000 -> BigDecimal(1_000_000) to "M"
        n < 1000 -> BigDecimal(1) to ""
        else -> {
            val variantM = nDecimal.divide(BigDecimal(1_000_000), RoundingMode.HALF_UP)
            val variantK = nDecimal.divide(BigDecimal(1_000), RoundingMode.HALF_UP)

            if (Math.abs((variantM*BigDecimal(1_000_000) - nDecimal).toInt()) <= Math.abs((nDecimal - variantK*BigDecimal(1_000)).toInt())) {
                BigDecimal(1_000_000) to "M"
            } else {
                BigDecimal(1_000) to "K"
            }
        }
    }

    val digits = nDecimal.divide(divisor, RoundingMode.HALF_UP).toInt()

    return "$digits$suffix"
}


package heroes

import java.math.BigDecimal
import java.math.RoundingMode

fun readLn() = readLine()!! // string line
fun readInt() = readLn().toInt()

fun main() {
    val t = readInt()

    for (i in 0 until t) {
        val n = readInt()
        println(output(n))
    }
}

fun output(n: Int): String {
    val nDecimal = BigDecimal(n)

    val (divisor, suffix) = when {
        n >= 1_000_000 -> BigDecimal(1_000_000) to "M"
        n < 1000 -> BigDecimal(1) to ""
        else -> {
            val variantM = nDecimal.divide(BigDecimal(1_000_000), RoundingMode.HALF_UP)
            val variantK = nDecimal.divide(BigDecimal(1_000), RoundingMode.HALF_UP)

            if (variantM*BigDecimal(1_000_000) - nDecimal <= nDecimal - variantK*BigDecimal(1_000)) {
                BigDecimal(1_000_000) to "M"
            } else {
                BigDecimal(1_000) to "K"
            }
        }
    }

    val digits = nDecimal.divide(divisor, RoundingMode.HALF_UP).toInt()

    return "$digits$suffix"
}


package heroes

import java.math.BigDecimal
import java.math.RoundingMode

fun readLn() = readLine()!! // string line
fun readInt() = readLn().toInt()

fun main() {
    val t = readInt()

    for (i in 0 until t) {
        val n = readInt()
        println(output(n))
    }
}

fun output(n: Int): String {
    val (divisor, suffix) = when {
        n >= 500_000 -> BigDecimal(1_000_000) to "M"
        n >= 1000 -> BigDecimal(1_000) to "K"
        else -> BigDecimal(1) to ""
    }
    val nDecimal = BigDecimal(n)
    val digits = nDecimal.divide(divisor, RoundingMode.HALF_UP).toInt()

    return "$digits$suffix"
}


import java.math.BigDecimal
import java.math.RoundingMode

fun readLn() = readLine()!! // string line
fun readInt() = readLn().toInt()

fun main() {
    val t = readInt()

    for (i in 0 until t) {
        val n = readInt()
        println(output(n))
    }
}

fun output(n: Int): String {
    val nDecimal = BigDecimal(n)

    val (divisor, suffix) = when {
        n >= 1_000_000 -> BigDecimal(1_000_000) to "M"
        n < 1000 -> BigDecimal(1) to ""
        else -> {
            val variantM = nDecimal.divide(BigDecimal(1_000_000), RoundingMode.HALF_UP)
            val variantK = nDecimal.divide(BigDecimal(1_000), RoundingMode.HALF_UP)

            if (variantM*BigDecimal(1_000_000) - nDecimal <= nDecimal - variantK*BigDecimal(1_000)) {
                BigDecimal(1_000_000) to "M"
            } else {
                BigDecimal(1_000) to "K"
            }
        }
    }

    val digits = nDecimal.divide(divisor, RoundingMode.HALF_UP).toInt()

    return "$digits$suffix"
}


import java.util.ArrayList
import java.util.Collections
import java.util.Comparator
import java.util.HashMap
import java.util.HashSet
import java.util.Scanner

   fun main(args:Array<String>) {
    var sys_in = Scanner(System.`in`)
    var t = sys_in.nextInt()
    for (z in 0 until t)
    {
        var n = sys_in.nextInt()
        if(n<1000)
        {
        	n=n+0
		}
		else if(n<1000000)
		{
			n=n/100
			if(n%10>=5)
			n=n+10
			n=n/10
		}
		else
		{
			n=n/100000
			if(n%10>=5)
			n=n+10
			n=n/10
		}
		println(n)
    }
}


import java.util.ArrayList
import java.util.Collections
import java.util.Comparator
import java.util.HashMap
import java.util.HashSet
import java.util.Scanner

   fun main(args:Array<String>) {
    var sys_in = Scanner(System.`in`)
    var t = sys_in.nextInt()
    for (z in 0 until t)
    {
        var n = sys_in.nextInt()
        if(n<1000)
        {
        	n=n+0
		}
		else if(n<1000000)
		{
			n=n/100
			if(n%10>=5)
			n=n+10
			n=n/10
			print(n)
			println("K")
		}
		else
		{
			n=n/100000
			if(n%10>=5)
			n=n+10
			n=n/10
			print(n)
			println("M")
		}
    }
}


import java.util.ArrayList
import java.util.Collections
import java.util.Comparator
import java.util.HashMap
import java.util.HashSet
import java.util.Scanner

   fun main(args:Array<String>) {
    var sys_in = Scanner(System.`in`)
    var t = sys_in.nextInt()
    for (z in 0 until t)
    {
        var n = sys_in.nextInt()
        if(n<1000)
        {
        	println(n)
		}
		else if(n<1000000)
		{
			n=n/100
			if(n%10>=5)
			n=n+10
			n=n/10
			print(n)
			println("K")
		}
		else
		{
			n=n/100000
			if(n%10>=5)
			n=n+10
			n=n/10
			print(n)
			println("M")
		}
    }
}


import java.util.ArrayList
import java.util.Collections
import java.util.Comparator
import java.util.HashMap
import java.util.HashSet
import java.util.Scanner

   fun main(args:Array<String>) {
    var sys_in = Scanner(System.`in`)
    var t = sys_in.nextInt()
    for (z in 0 until t)
    {
        var n = sys_in.nextInt()
        if(n<1000)
        {
        	n=n+0
		}
		else if(n<1000000)
		{
			n=n/100
			if(n%10>=5)
			n=n+10
			n=n/10
			print(n)
			println(K)
		}
		else
		{
			n=n/100000
			if(n%10>=5)
			n=n+10
			n=n/10
			print(n)
			println(M)
		}
    }
}


import java.util.ArrayList
import java.util.Collections
import java.util.Comparator
import java.util.HashMap
import java.util.HashSet
import java.util.Scanner

   fun main(args:Array<String>) {
    var sys_in = Scanner(System.`in`)
    var t = sys_in.nextInt()
    for (z in 0 until t)
    {
        var n = sys_in.nextInt()
        if(n<1000)
        {
        	n=n+0
		}
		else if(n<1000000)
		{
			n=n/100
			if(n%10>=5)
			n=n+10
			n=n/10
			if(n>=1000)
			{
			    n=n/100
    			if(n%10>=5)
    			n=n+10
    			n=n/
    			print(n)
			    println("M")
			}
			else{
			print(n)
			println("K")
			}
		}
		else
		{
			n=n/100000
			if(n%10>=5)
			n=n+10
			n=n/10
			print(n)
			println("M")
		}
    }
}


import java.util.ArrayList
import java.util.Collections
import java.util.Comparator
import java.util.HashMap
import java.util.HashSet
import java.util.Scanner

   fun main(args:Array<String>) {
    var sys_in = Scanner(System.`in`)
    var t = sys_in.nextInt()
    for (z in 0 until t)
    {
        var n = sys_in.nextInt()
        if(n<1000)
        {
        	println(n)
		}
		else if(n<1000000)
		{
			n=n/100
			if(n%10>=5)
			n=n+10
			n=n/10
			if(n>=1000)
			{
			    n=n/100
    			if(n%10>=5)
    			n=n+10
    			n=n/10
    			print(n)
			    println("M")
			}
			else{
			print(n)
			println("K")
			}
		}
		else
		{
			n=n/100000
			if(n%10>=5)
			n=n+10
			n=n/10
			print(n)
			println("M")
		}
    }
}


import kotlin.math.roundToInt

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    var ans = "2000M"

    if (n < 1000) ans = n.toString()
    else if (n in 1000 until 999_999) {
        ans = (n / 1000.0).roundToInt().toString() + "K"
    }
    else if (ans == "100K") {
        ans = "1M"
    }
    else if (n < 2_000_000_000) ans = (n / 1_000_000.0).roundToInt().toString() + "M"
    return ans
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        val n = readLn().toLong()
        println(display(n))
    }
}


import kotlin.math.roundToInt

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    return when {
        n < 1000 -> n.toString()
        n in 1000 until 999_999 -> (n / 1000.0).roundToInt().toString() + "K"
        n < 2_000_000_000 -> (n / 1_000_000.0).roundToInt().toString() + "M"
        else -> "2000M"
    }
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        val n = readLn().toLong()
        println(display(n))
    }
}


import kotlin.math.roundToInt

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    return when {
        n < 1000 -> n.toString()
        n in 1000 until 1_000_000-2 -> (n / 1000.0).roundToInt().toString() + "K"
        n <= 999_999L -> "999K"
        n < 2_000_000_000 -> (n / 1_000_000.0).roundToInt().toString() + "M"
        else -> "2000M"
    }
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        val n = readLn().toLong()
        println(display(n))
    }
}


fun display(n: Long): String {
    var ans = "2000M"

    if (n < 1000) ans = n.toString()
    else if (n in 1000 until 999_999) {
        ans = (n / 1000.0).roundToInt().toString() + "K"
    }
    else if (ans == "1000K") {
        ans = "1M"
    }
    else if (n < 2_000_000_000) ans = (n / 1_000_000.0).roundToInt().toString() + "M"
    return ans
}


import kotlin.math.roundToInt

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    return when {
        n < 1000 -> n.toString()
        n in 1000 until 999_000 -> (n / 1000.0).roundToInt().toString() + "K"
        n < 2_000_000_000 -> (n / 1_000_000.0).roundToInt().toString() + "M"
        else -> "2000M"
    }
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        val n = readLn().toLong()
        println(display(n))
    }
}


private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    if (n < 1000) return n.toString()
    else if (n in 1000 until 999_999) {
        val last = n % 1000
        if (last >= 500) {
            return ((n / 1000) + 1).toString() + "K"
        }
        return (n / 1000.0).toString() + "K"
    } else {
        val last = n % 1_000_000
        if (last >= 500_000) {
            return ((n / 1_000_000) + 1).toString() + "M"
        }
        return (n / 1_000_000).toString() + "M"
    }
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        var n = readLn().toLong()
        println(display(n))
    }
//    assert()
}


import kotlin.math.roundToInt

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    var ans = "2000M"

    if (n < 1000) ans = n.toString()
    else if (n in 1000 until 999_999) {
        ans = (n / 1000.0).roundToInt().toString() + "K"
    }
    if (ans == "1000K") {
        ans = "1M"
    } else if (n in 1_000_000..2_000_000_000) {
        ans = (n / 1_000_000.0).roundToInt().toString() + "M"
    }
    return ans
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        val n = readLn().toLong()
        println(display(n))
    }
}


import kotlin.math.roundToInt

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    var ans = "2000M"

    if (n < 1000) ans = n.toString()
    else if (n in 1000 until 1_000_000) {
        ans = (n / 1000.0).roundToInt().toString() + "K"
        if (ans == "1000K") {
            ans = "1M"
    }
    } else if (n in 1_000_000..2_000_000_000) {
        ans = (n / 1_000_000.0).roundToInt().toString() + "M"
    }
    return ans
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        val n = readLn().toLong()
        println(display(n))
    }
}


import kotlin.math.roundToInt

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    return when {
        n < 1000 -> n.toString()
        n in 1000 until 999_999 -> (n / 1000.0).roundToInt().toString() + "K"
        else -> (n / 1_000_000.0).roundToInt().toString() + "M"
    }
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        val n = readLn().toLong()
        println(display(n))
    }
}


import kotlin.math.roundToInt
import kotlin.test.assertTrue

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    return when {
        n < 1000 -> n.toString()
        n in 1000 until 500_000 -> (n / 1000.0).roundToInt().toString() + "K"
        else -> (n / 1_000_000.0).roundToInt().toString() + "M"
    }
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        val n = readLn().toLong()
        println(display(n))
    }
}

fun assert() {
    assertTrue { display(999) == "999" }
    assertTrue { display(0) == "0" }

    assertTrue { display(1785L) == "2K" }

    assertTrue { display(999_999L) == "1M" }

    assertTrue { display(35499710L) == "35M" }

    assertTrue { display(2_000_000_000) == "2000M" }
    assertTrue { display(5_000_000) == "5M" }

}


import kotlin.math.roundToInt

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    return when {
        n < 1000 -> n.toString()
        n in 1000 until 500_000 -> (n / 1000.0).roundToInt().toString() + "K"
        else -> (n / 1_000_000.0).roundToInt().toString() + "M"
    }
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        val n = readLn().toLong()
        println(display(n))
    }
}


import kotlin.math.roundToInt

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    var ans = "2000M"

    if (n < 1000) ans = n.toString()
    else if (n in 1000 until 999_999) {
        ans = (n / 1000.0).roundToInt().toString() + "K"
        if (ans == "1000K") {
            ans = "1M"
    }
    } else if (n in 1_000_000..2_000_000_000) {
        ans = (n / 1_000_000.0).roundToInt().toString() + "M"
    }
    return ans
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        val n = readLn().toLong()
        println(display(n))
    }
}


private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun display(n: Long): String {
    if (n < 1000) return n.toString()
    else if (n in 1000 until 500_000) {
        val last = n % 1000
        if (last >= 500) {
            return ((n / 1000) + 1).toString() + "K"
        }
        return (n / 1000.0).toString() + "K"
    } else {
        val last = n % 1_000_000
        if (last >= 500_000) {
            return ((n / 1_000_000) + 1).toString() + "M"
        }
        return (n / 1_000_000).toString() + "M"
    }
}

fun main() {
    val t = readInt()
    for (i in 1..t) {
        var n = readLn().toLong()
        println(display(n))
    }
//    assert()
}


import kotlin.math.roundToInt

fun main(args: Array<String>) {
            val n = readLine()
            val numbers = generateSequence(::readLine).map { it.toInt() }

            val numbersToPrint = mutableListOf<String>()

            numbers.forEach {
                when (it) {
                    in 0..999 -> {
                        numbersToPrint += it.toString()
                    }
                    in 1000..999000 -> {
                        numbersToPrint += "${(it / 1000.0).roundToInt()}K"
                    }
                    in 999_000..2000_000_000 -> {
                        numbersToPrint += "${(it / 1_000_000.0).roundToInt()}M"
                    }
                }
            }
            println(numbersToPrint.joinToString("\n"))
}


import kotlin.math.roundToInt

fun main(args: Array<String>) {
            val n = readLine()
            val numbers = generateSequence(::readLine).map { it.toInt() }

            val numbersToPrint = mutableListOf<String>()

            numbers.forEach {
                when (it) {
                    in 0..999 -> {
                        numbersToPrint += it.toString()
                    }
                    in 1000..999000 -> {
                        numbersToPrint += "${(it / 1000.0).roundToInt()}K"
                    }
                    in 1_000_000..2000_000_000 -> {
                        numbersToPrint += "${(it / 1_000_000.0).roundToInt()}M"
                    }
                }
            }
            println(numbersToPrint.joinToString("\n"))
}


import kotlin.math.roundToInt

fun main(args: Array<String>) {
            val n = readLine()
            val numbers = generateSequence(::readLine).map { it.toInt() }

            val numbersToPrint = mutableListOf<String>()

            numbers.forEach {
                when (it) {
                    in 0..999 -> {
                        numbersToPrint += it.toString()
                    }
                    in 1000..999000 -> {
                        numbersToPrint += "${(it / 1000.0).roundToInt()}K"
                    }
                    in 999_000..999499 -> {
                        numbersToPrint += "${(it / 1000.0).roundToInt()}K"
                    }
                    in 999_500..999_999 -> {
                        numbersToPrint += "${(it / 1_000_000.0).roundToInt()}M"
                    }
                    in 999_000..2000_000_000 -> {
                        numbersToPrint += "${(it / 1_000_000.0).roundToInt()}M"
                    }
                }
            }
            println(numbersToPrint.joinToString("\n"))
}


import kotlin.math.roundToInt
fun readInts() = readLine()!!.split(' ').map { it.toInt() }
fun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine()!! }.constrainOnce().take(limit)

fun main(args: Array<String>) {
            val numbers = readInts()

            val numbersToPrint = mutableListOf<String>()

            numbers.forEach {
                when (it) {
                    in 0..999 -> {
                        numbersToPrint += it.toString()
                    }
                    in 1000..999000 -> {
                        numbersToPrint += "${(it / 1000.0).roundToInt()}K"
                    }
                    in 1_000_000..2000_000_000 -> {
                        numbersToPrint += "${(it / 1_000_000.0).roundToInt()}M"
                    }
                }
            }
            println(numbersToPrint.jointToString(" "))
}


import kotlin.math.roundToInt

fun main(args: Array<String>) {
            val numbers = generateSequence(::readLine).map { it.toInt() }

            val numbersToPrint = mutableListOf<String>()

            numbers.forEach {
                when (it) {
                    in 0..999 -> {
                        numbersToPrint += it.toString()
                    }
                    in 1000..999000 -> {
                        numbersToPrint += "${(it / 1000.0).roundToInt()}K"
                    }
                    in 1_000_000..2000_000_000 -> {
                        numbersToPrint += "${(it / 1_000_000.0).roundToInt()}M"
                    }
                }
            }
            println(numbersToPrint.joinToString("\n"))
}


import java.util.*
import kotlin.math.ceil
import kotlin.math.round

fun main(args: Array<String>) {
    val T = readLine()!!.toInt()
    for (t in 1..T) {
        val n = readLine()!!.toInt()
        if (n < 1000) {
            println(n)
        } else if (n < 500_000) {
            val result = round(n / 1_000.0).toInt()
            println("${result}K")
        } else {
            val result = round(n / 1_000_000.0).toInt()
            println("${result}M")
        }
    }

}


import java.util.*
import kotlin.math.ceil
import kotlin.math.round

fun main(args: Array<String>) {
    val T = readLine()!!.toInt()
    for (t in 1..T) {
        val n = readLine()!!.toInt()

        if (n < 1000) {
            println(n)
        } else if (round(n / 1_000.0).toInt() < 1_000) {
            val result = round(n / 1_000.0).toInt()
            println("${result}K")
        } else {
            val result = round(n / 1_000_000.0).toInt()
            println("${result}M")
        }
    }

}


import java.math.BigDecimal
import java.math.MathContext
import java.math.RoundingMode
import java.util.*
import kotlin.math.ceil
import kotlin.math.round

fun main(args: Array<String>) {
    val T = readLine()!!.toInt()
    for (t in 1..T) {
        val n = readLine()!!.toInt()

        if (n < 1000) {
            println(n)
            continue;
        }

        var result = BigDecimal(n/1_000.0).setScale(0, RoundingMode.HALF_UP).toInt()
        if (result < 1000) {
            println("${result}K")
            continue
        }

        result = BigDecimal(n/1_000_000.0).setScale(0, RoundingMode.HALF_UP).toInt()
        println("${result}M")
    }

}


import java.util.*
import kotlin.math.ceil
import kotlin.math.round

fun main(args: Array<String>) {
    val T = readLine()!!.toInt()
    for (t in 1..T) {
        val n = readLine()!!.toInt()

        if (n < 1000) {
            println(n)
        } else if ((round(n / 1_000.0) + 1e-6).toInt() < 1_000) {
            val result = (round(n / 1_000.0) + 1e-6).toInt()
            println("${result}K")
        } else {
            val result = round((n / 1_000_000.0) + 1e-6).toInt()
            println("${result}M")
        }
    }

}


import kotlin.math.round

fun main(args: Array<String>) {
    val T = readLine()!!.toInt()
    for (t in 1..T) {
        val n = readLine()!!.toInt()
        if (n < 1000) {
            println(n)
        } else {
            if (n < 1_000_000 && round(n / 1_000.0).toInt() < 1_000) {
                val result = round(n / 1_000.0).toInt()
                println("${result}K")
            } else {
                val result = round(n / 1_000_000.0).toInt()
                println("${result}M")
            }
        }
    }

}


import java.util.*
import kotlin.math.ceil
import kotlin.math.round

fun main(args: Array<String>) {
    val T = readLine()!!.toInt()
    for (t in 1..T) {
        val n = readLine()!!.toInt()

        if (n < 1000) {
            println(n)
        } else if ((round(n / 1_000.0) + 1e-6).toInt() < 1_000) {
            val result = round(n / 1_000.0).toInt()
            println("${result}K")
        } else {
            val result = round((n / 1_000_000.0) + 1e-6).toInt()
            println("${result}M")
        }
    }

}


import java.lang.Exception
import java.math.*
import kotlin.math.*

fun solve() {
    val like = readInt()
    if (like < 1000) {
        println(like)
        return;
    }
    val l = round(like.toDouble() / 1000 + 0.00000001).toInt()
    if (l < 1000) {
        println(l.toString() + "K")
        return
    }
    println(round(like.toDouble() / 1000000 + 0.00000001).toInt().toString() + "M")
}

fun main() {
    var t = 1;
    t = readInt()
    while (t-- != 0) {
        solve()
   //     t++
    }
}

private fun readln() = readLine()!!
private fun readInt() = readln().toInt()
private fun readStrings() = readln().split(" ")
private fun readInts() = readStrings().map { it.toInt() }
class yesno(y: String, n: String) {
    private val yes = y
    private val no = n
    operator fun invoke(ok: Boolean): String { return if (ok) this.yes else this.no }
}

fun prefixFunction(s: CharArray): Array<Int> {
    val n = s.size
    val p = Array(n) {0}
    for (i in 1 until n) {
        var j = p[i - 1]
        while (j > 0 && s[j] != s[i])
            j = p[j - 1]
        if (s[i] == s[j])
            j++
        p[i] = j
    }
    return p
}

fun KnuthMorris(s: CharArray, t: CharArray): Int {
    val p = prefixFunction(s + "#".toCharArray() + t)
    val n = s.size
    val m = t.size
    for (i in n + 1 .. n + m)
        if (p[i] == n)
            return i - n - n
    return -1
}


import java.lang.Exception
import java.math.*
import kotlin.math.*

fun solve() {
    val like = readInt()
    if (like < 1000) {
        println(like)
        return;
    }
    val l = round(like.toDouble() / 1000).toInt()
    if (l < 1000) {
        println(l.toString() + "K")
        return
    }
    println(round(like.toDouble() / 1000000).toInt().toString() + "M")
}

fun main() {
    var t = 1;
    t = readInt()
    while (t-- != 0) {
        solve()
   //     t++
    }
}

private fun readln() = readLine()!!
private fun readInt() = readln().toInt()
private fun readStrings() = readln().split(" ")
private fun readInts() = readStrings().map { it.toInt() }
class yesno(y: String, n: String) {
    private val yes = y
    private val no = n
    operator fun invoke(ok: Boolean): String { return if (ok) this.yes else this.no }
}

fun prefixFunction(s: CharArray): Array<Int> {
    val n = s.size
    val p = Array(n) {0}
    for (i in 1 until n) {
        var j = p[i - 1]
        while (j > 0 && s[j] != s[i])
            j = p[j - 1]
        if (s[i] == s[j])
            j++
        p[i] = j
    }
    return p
}

fun KnuthMorris(s: CharArray, t: CharArray): Int {
    val p = prefixFunction(s + "#".toCharArray() + t)
    val n = s.size
    val m = t.size
    for (i in n + 1 .. n + m)
        if (p[i] == n)
            return i - n - n
    return -1
}


import java.lang.Exception
import java.math.*
import kotlin.math.*

fun solve() {
    println(round(6.5))
    val like = readInt()
    if (like < 1000) {
        println(like)
        return;
    }
    val l = round(like.toDouble() / 1000 + 0.001).toInt()
    if (l < 1000) {
        println(l.toString() + "K")
        return
    }
    println(round(like.toDouble() / 1000000 + 0.000001).toInt().toString() + "M")
}

fun main() {
    var t = 1;
    t = readInt()
    while (t-- != 0) {
        solve()
   //     t++
    }
}

private fun readln() = readLine()!!
private fun readInt() = readln().toInt()
private fun readStrings() = readln().split(" ")
private fun readInts() = readStrings().map { it.toInt() }
class yesno(y: String, n: String) {
    private val yes = y
    private val no = n
    operator fun invoke(ok: Boolean): String { return if (ok) this.yes else this.no }
}

fun prefixFunction(s: CharArray): Array<Int> {
    val n = s.size
    val p = Array(n) {0}
    for (i in 1 until n) {
        var j = p[i - 1]
        while (j > 0 && s[j] != s[i])
            j = p[j - 1]
        if (s[i] == s[j])
            j++
        p[i] = j
    }
    return p
}

fun KnuthMorris(s: CharArray, t: CharArray): Int {
    val p = prefixFunction(s + "#".toCharArray() + t)
    val n = s.size
    val m = t.size
    for (i in n + 1 .. n + m)
        if (p[i] == n)
            return i - n - n
    return -1
}


import java.lang.Exception
import java.math.*
import kotlin.math.*

fun solve() {
    var like = readInt()
    if (like < 1000) {
        println(like)
        return;
    }
    like = round(like.toDouble() / 1000).toInt()
    if (like < 1000) {
        println(like.toString() + "K")
        return
    }
    println(round(like.toDouble() / 1000).toInt().toString() + "M")
}

fun main() {
    var t = 1;
    t = readInt()
    while (t-- != 0) {
        solve()
   //     t++
    }
}

private fun readln() = readLine()!!
private fun readInt() = readln().toInt()
private fun readStrings() = readln().split(" ")
private fun readInts() = readStrings().map { it.toInt() }
class yesno(y: String, n: String) {
    private val yes = y
    private val no = n
    operator fun invoke(ok: Boolean): String { return if (ok) this.yes else this.no }
}

fun prefixFunction(s: CharArray): Array<Int> {
    val n = s.size
    val p = Array(n) {0}
    for (i in 1 until n) {
        var j = p[i - 1]
        while (j > 0 && s[j] != s[i])
            j = p[j - 1]
        if (s[i] == s[j])
            j++
        p[i] = j
    }
    return p
}

fun KnuthMorris(s: CharArray, t: CharArray): Int {
    val p = prefixFunction(s + "#".toCharArray() + t)
    val n = s.size
    val m = t.size
    for (i in n + 1 .. n + m)
        if (p[i] == n)
            return i - n - n
    return -1
}


import java.lang.Exception
import java.math.*
import kotlin.math.*

fun solve() {
    val like = readInt()
    if (like < 1000) {
        println(like)
        return;
    }
    val l = round(like.toDouble() / 1000 + 0.000001).toInt()
    if (l < 1000) {
        println(l.toString() + "K")
        return
    }
    println(round(like.toDouble() / 1000000 + 0.000001).toInt().toString() + "M")
}

fun main() {
    var t = 1;
    t = readInt()
    while (t-- != 0) {
        solve()
   //     t++
    }
}

private fun readln() = readLine()!!
private fun readInt() = readln().toInt()
private fun readStrings() = readln().split(" ")
private fun readInts() = readStrings().map { it.toInt() }
class yesno(y: String, n: String) {
    private val yes = y
    private val no = n
    operator fun invoke(ok: Boolean): String { return if (ok) this.yes else this.no }
}

fun prefixFunction(s: CharArray): Array<Int> {
    val n = s.size
    val p = Array(n) {0}
    for (i in 1 until n) {
        var j = p[i - 1]
        while (j > 0 && s[j] != s[i])
            j = p[j - 1]
        if (s[i] == s[j])
            j++
        p[i] = j
    }
    return p
}

fun KnuthMorris(s: CharArray, t: CharArray): Int {
    val p = prefixFunction(s + "#".toCharArray() + t)
    val n = s.size
    val m = t.size
    for (i in n + 1 .. n + m)
        if (p[i] == n)
            return i - n - n
    return -1
}


import java.lang.Exception
import java.math.*
import kotlin.math.*

fun solve() {
    var like = readInt()
    if (like < 1000) {
        println(like)
        return;
    }
    like = round(like.toDouble() / 1000).toInt()
    if (like < 1000) {
        println(like.toString() + "K")
        return
    }
    println((like / 1000).toString() + "M")
}

fun main() {
    var t = 1;
    t = readInt()
    while (t-- != 0) {
        solve()
   //     t++
    }
}

private fun readln() = readLine()!!
private fun readInt() = readln().toInt()
private fun readStrings() = readln().split(" ")
private fun readInts() = readStrings().map { it.toInt() }
class yesno(y: String, n: String) {
    private val yes = y
    private val no = n
    operator fun invoke(ok: Boolean): String { return if (ok) this.yes else this.no }
}

fun prefixFunction(s: CharArray): Array<Int> {
    val n = s.size
    val p = Array(n) {0}
    for (i in 1 until n) {
        var j = p[i - 1]
        while (j > 0 && s[j] != s[i])
            j = p[j - 1]
        if (s[i] == s[j])
            j++
        p[i] = j
    }
    return p
}

fun KnuthMorris(s: CharArray, t: CharArray): Int {
    val p = prefixFunction(s + "#".toCharArray() + t)
    val n = s.size
    val m = t.size
    for (i in n + 1 .. n + m)
        if (p[i] == n)
            return i - n - n
    return -1
}


import java.util.*
import kotlin.math.roundToInt

fun main(args: Array<String>) {
    val input = Scanner(System.`in`)
    val n = input.nextInt()

    var numOfLikes: Int
    for (x in 0 until n) {
        numOfLikes = input.nextInt()
        if (numOfLikes < 1000) {
            println(numOfLikes)
        } else if (numOfLikes / 1000 < 999) {
            print((numOfLikes / 1000.0).roundToInt())
            println("K")
        } else {
            print((numOfLikes / 1000000.0).roundToInt())
            println("M")
        }
    }
}


import java.util.*
import kotlin.math.roundToInt

fun main(args: Array<String>) {
    val input = Scanner(System.`in`)
    val n = input.nextInt()

    var numOfLikes: Int
    for (x in 0 until n) {
        numOfLikes = input.nextInt()
        if (numOfLikes < 1000) {
            println(numOfLikes)
        } else if (numOfLikes / 1000.0 < 999.995) {
            print((numOfLikes / 1000.0).roundToInt())
            println("K")
        } else {
            print((numOfLikes / 1000000.0).roundToInt())
            println("M")
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
#define pb push_back
#define INF 1000000000
#define mp make_pair
#define MOD 1000000007
#define F first
#define S second
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPD(i,n) for(int i=(n);i>=0;i--)
#define FORD(i,a,b) for(int i=(a);i>=b;i--)
#define all(v) v.begin(),v.end()
#define itr ::iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remin(a,b) (a) = min((a),(b))
#define remax(a,b) (a) = max((a),(b))

int n;
int depth[100005];
vi adj[100005];

void dfs(int s,int par,int dep){
  depth[s] = dep;
  for(auto x:adj[s]){
    if(x != par) dfs(x,s,dep+1);
  }
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	if(n == 1){
	  cout << "0\n";
	  return 0;
	}
	REP(i,n-1){
	  int u,v;
	  cin >> u >> v;
	  adj[u].pb(v);adj[v].pb(u);
	}
	dfs(1,-1,0);
	double res=0,cnt=0;
	FOR(i,2,n+1){
	  if(adj[i].size() == 1) {
	    res += depth[i];
	    cnt ++;
	  }
	}
	cout << res/cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
#define pb push_back
#define INF 1000000000
#define mp make_pair
#define MOD 1000000007
#define F first
#define S second
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPD(i,n) for(int i=(n);i>=0;i--)
#define FORD(i,a,b) for(int i=(a);i>=b;i--)
#define all(v) v.begin(),v.end()
#define itr ::iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remin(a,b) (a) = min((a),(b))
#define remax(a,b) (a) = max((a),(b))

int n;
int depth[100005];
long double prob[100005];
vi adj[100005];

void dfs(int s,int par,int dep){
  depth[s] = dep;
  for(auto x:adj[s]){
    if(x != par){
      if(s == 1){
        prob[x] = adj[s].size();
      }
      else{
        prob[x] = prob[s]*(adj[s].size()-1);
      }
      dfs(x,s,dep+1);
    }
  }
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	if(n == 1){
	  cout << "0\n";
	  return 0;
	}
	REP(i,n-1){
	  int u,v;
	  cin >> u >> v;
	  adj[u].pb(v);adj[v].pb(u);
	}
	prob[1] = 1;
	dfs(1,-1,0);
	long double ans = 0;
	FOR(i,2,n+1){
	  if(adj[i].size() == 1) ans += depth[i]/prob[i];
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
#define pb push_back
#define INF 1000000000
#define mp make_pair
#define MOD 1000000007
#define F first
#define S second
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPD(i,n) for(int i=(n);i>=0;i--)
#define FORD(i,a,b) for(int i=(a);i>=b;i--)
#define all(v) v.begin(),v.end()
#define itr ::iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remin(a,b) (a) = min((a),(b))
#define remax(a,b) (a) = max((a),(b))

int n;
int depth[100005];
vi adj[100005];

double dfs(int s,int par){
  double cur = 0;
  if (s == 1){
    for(auto x: adj[s]) cur += dfs(x,s)/((double)adj[s].size());
    return cur+1;
  }
  if(adj[s].size() == 1) return 0;
  for(auto x:adj[s]){
    if(x != par){
      cur += dfs(x,s)/((double)(adj[s].size()-1));
    }
  }
  return cur+1;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	if(n == 1){
	  cout << "0\n";
	  return 0;
	}
	REP(i,n-1){
	  int u,v;
	  cin >> u >> v;
	  adj[u].pb(v);adj[v].pb(u);
	}
	cout << dfs(1,-1);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
vector<ll> v[100005];
bool vis[100005];
ll level[100005];
set<ll> s;
void input()
{
	cin>>n;
	n--;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		s.insert(x);
		s.insert(y);
		v[x-1].push_back(y-1);
		v[y-1].push_back(x-1);
	}

}
void bfs(ll s)
{
	vis[s]=true;
	level[s]=0;
	queue<ll> q;
	q.push(s);
	ll i;
	while(!q.empty())
	{
		ll p=q.front();
		q.pop();
		for(i=0;i<=v[p].size()-1;i++)
		{
			if(vis[v[p][i]]==false)
			{
				level[v[p][i]]=level[p]+1;
				vis[v[p][i]]=true;
				q.push(v[p][i]);
			}
		}
	}

}
void solve()
{
	input();
	bfs(0);
	ll c=0;
	long double sum=0;
	for(auto x : s)
	{
		if(v[x-1].size()==1 && x!=1)
		{
			sum=sum+level[x-1];
			c++;
		}
	}
	long double p=sum/((double)c);
	cout<<setprecision(20)<<fixed<<p;
}
int main()
{
	solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,p;
vector<ll> v[100005];
bool vis[100005];
void input()
{
	cin>>n;
	p=n;
	n--;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		v[x-1].push_back(y-1);
		v[y-1].push_back(x-1);
	}

}
double dfs(ll s)
{
	vis[s]=true;
	double sum=0;
	double k=0;
	for(ll i=0;i<=v[s].size()-1;i++)
	{
		if(vis[v[s][i]]==false)
		{
			sum+=dfs(v[s][i])+1,k+=1;
		}
    }
    if(k)
    {
    	return (sum/k);
    }
    return(0);

}
void solve()
{
	input();
	if(p==1)
	{
		cout<<setprecision(20)<<fixed<<0.0;

	}
	else
	{
		cout<<setprecision(20)<<fixed<<dfs(0);
	}

}
int main()
{
	solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
vector<ll> v[100005];
bool vis[100005];
ll level[100005];
ll t2;
long double prob[100005];
void input()
{
	cin>>n;
    t2=n;
	n--;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		v[x-1].push_back(y-1);
		v[y-1].push_back(x-1);
	}

}
void bfs(ll s)
{
	vis[s]=true;
	level[s]=0;
	prob[s]=1.0;
	queue<ll> q;
	q.push(s);
	ll i;
	while(!q.empty())
	{
		ll p=q.front();
		q.pop();
		for(i=0;i<=v[p].size()-1;i++)
		{
			if(vis[v[p][i]]==false)
			{
				level[v[p][i]]=level[p]+1;
				vis[v[p][i]]=true;
				q.push(v[p][i]);
				if(p!=0)
				{
					prob[v[p][i]]=(prob[p])/((long double)(v[p].size()-1));
				}
				else
				{
					prob[v[p][i]]=(prob[p])/((long double)(v[p].size()));
				}
			}
		}
	}

}
void solve()
{
	input();
	bfs(0);
	long double sum=0;
	for(ll i=1;i<=t2-1;i++)
	{
		if(v[i].size()==1)
		{
			sum+=prob[i]*level[i];

		}
	}
	cout<<setprecision(20)<<fixed<<sum;
}
int main()
{
	solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
vector<ll> v[100005];
bool vis[100005];
ll level[100005];
set<ll> s;
void input()
{
	cin>>n;
	n--;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		s.insert(x);
		s.insert(y);
		v[x-1].push_back(y-1);
		v[y-1].push_back(x-1);
	}

}
void bfs(ll s)
{
	vis[s]=true;
	level[s]=0;
	queue<ll> q;
	q.push(s);
	ll i;
	while(!q.empty())
	{
		ll p=q.front();
		q.pop();
		for(i=0;i<=v[p].size()-1;i++)
		{
			if(vis[v[p][i]]==false)
			{
				level[v[p][i]]=level[p]+1;
				vis[v[p][i]]=true;
				q.push(v[p][i]);
			}
		}
	}

}
void solve()
{
	input();
	bfs(0);
	ll c=0;
	long double sum=0;
	for(auto x : s)
	{
		if(v[x-1].size()==1)
		{
			sum=sum+level[x-1];
			c++;
		}
	}
	if(c==0)
	{
		long double sum1=0;
		ll p2=0,i;
		for(i=0;i<=v[0].size()-1;i++)
		{

			if(v[v[0][i]].size()==2)
			{
				if(v[v[0][i]][1]==0)
				{
				    sum1+=level[v[v[0][i]][0]]+1;
				}
				else
				{
				    sum1+=level[v[v[0][i]][1]]+1;
				}
			}
			p2++;
		}

		long double p1=sum1/((double)p2);
		cout<<setprecision(20)<<fixed<<p1;
	}
	else
	{
		long double p=sum/((double)c);
		cout<<setprecision(20)<<fixed<<p;
	}

}
int main()
{
	solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
vector<ll> v[100005];
bool vis[100005];
void input()
{
	cin>>n;
	n--;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		v[x-1].push_back(y-1);
		v[y-1].push_back(x-1);
	}

}
double dfs(ll s)
{
	vis[s]=true;
	double sum=0;
	double k=0;
	for(ll i=0;i<=v[s].size()-1;i++)
	{
		if(vis[v[s][i]]==false)
		{
			sum+=dfs(v[s][i])+1,k+=1;
		}
    }
    if(k)
    {
    	return (sum/k);
    }
    return(0);

}
void solve()
{
	input();
	cout<<setprecision(20)<<fixed<<dfs(0);

}
int main()
{
	solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
vector<ll> v[100005];
bool vis[100005];
ll level[100005];
set<ll> s;
void input()
{
	cin>>n;
	n--;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		s.insert(x);
		s.insert(y);
		v[x-1].push_back(y-1);
		v[y-1].push_back(x-1);
	}

}
void bfs(ll s)
{
	vis[s]=true;
	level[s]=0;
	queue<ll> q;
	q.push(s);
	ll i;
	while(!q.empty())
	{
		ll p=q.front();
		q.pop();
		for(i=0;i<=v[p].size()-1;i++)
		{
			if(vis[v[p][i]]==false)
			{
				level[v[p][i]]=level[p]+1;
				vis[v[p][i]]=true;
				q.push(v[p][i]);
			}
		}
	}

}
void solve()
{
	input();
	bfs(0);
	ll c=0;
	long double sum=0;
	for(auto x : s)
	{
		if(v[x-1].size()==1)
		{
			sum=sum+level[x-1];
			c++;
		}
	}
	if(c==0)
	{
		long double a1=1.0;
		cout<<setprecision(20)<<fixed<<a1;
	}
	else
	{
		long double p=sum/((double)c);
		cout<<setprecision(20)<<fixed<<p;
	}

}
int main()
{
	solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
vector<ll> v[100005];
bool vis[100005];
ll level[100005];
set<ll> s;
void input()
{
	cin>>n;
	n--;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		s.insert(x);
		s.insert(y);
		v[x-1].push_back(y-1);
		v[y-1].push_back(x-1);
	}

}
void bfs(ll s)
{
	vis[s]=true;
	level[s]=0;
	queue<ll> q;
	q.push(s);
	ll i;
	while(!q.empty())
	{
		ll p=q.front();
		q.pop();
		for(i=0;i<=v[p].size()-1;i++)
		{
			if(vis[v[p][i]]==false)
			{
				level[v[p][i]]=level[p]+1;
				vis[v[p][i]]=true;
				q.push(v[p][i]);
			}
		}
	}

}
void solve()
{
	input();
	bfs(0);
	ll c=0;
	long double sum=0;
	for(auto x : s)
	{
		if(v[x-1].size()==1)
		{
			sum=sum+level[x-1];
			c++;
		}
	}
	long double p=sum/((double)c);
	cout<<setprecision(7)<<fixed<<p;
}
int main()
{
	solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
vector<ll> v[100005];
bool vis[100005];
ll level[100005];
ll t2;
long double prob[100005];
void input()
{
	cin>>n;
    t2=n;
	n--;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		v[x-1].push_back(y-1);
		v[y-1].push_back(x-1);
	}

}
void bfs(ll s)
{
	vis[s]=true;
	level[s]=0;
	prob[s]=1.0;
	queue<ll> q;
	q.push(s);
	ll i;
	while(!q.empty())
	{
		ll p=q.front();
		q.pop();
		for(i=0;i<=v[p].size()-1;i++)
		{
			if(vis[v[p][i]]==false)
			{
				level[v[p][i]]=level[p]+1;
				vis[v[p][i]]=true;
				q.push(v[p][i]);
				if(p!=0)
				{
					prob[v[p][i]]=(prob[p])/((long double)(v[p].size()-1));
				}
				else
				{
					prob[v[p][i]]=(prob[p])/((long double)(v[p].size()));
				}
			}
		}
	}

}
void solve()
{
	input();
	bfs(0);
	if(n==1)
	{
		cout<<setprecision(20)<<fixed<<0.0;

	}
	else
	{
		long double sum=0;
		for(ll i=1;i<=t2-1;i++)
		{
			if(v[i].size()==1)
			{
				sum+=prob[i]*level[i];

			}
		}
		cout<<setprecision(20)<<fixed<<sum;

	}

}
int main()
{
	solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
vector<ll> v[100005];
bool vis[100005];
ll level[100005];
ll t2;
long double prob[100005];
void input()
{
	cin>>n;
    t2=n;
	n--;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		v[x-1].push_back(y-1);
		v[y-1].push_back(x-1);
	}

}
void bfs(ll s)
{
	vis[s]=true;
	level[s]=0;
	prob[s]=1.0;
	queue<ll> q;
	q.push(s);
	ll i;
	while(!q.empty())
	{
		ll p=q.front();
		q.pop();
		for(i=0;i<=v[p].size()-1;i++)
		{
			if(vis[v[p][i]]==false)
			{
				level[v[p][i]]=level[p]+1;
				vis[v[p][i]]=true;
				q.push(v[p][i]);
				if(p!=0)
				{
					prob[v[p][i]]=(prob[p])/((long double)(v[p].size()-1));
				}
				else
				{
					prob[v[p][i]]=(prob[p])/((long double)(v[p].size()));
				}
			}
		}
	}

}
void solve()
{
	input();
	if(t2==1)
	{
		cout<<setprecision(20)<<fixed<<0.0;

	}

	else
	{
		bfs(0);
		long double sum=0;
		for(ll i=1;i<=t2-1;i++)
		{
			if(v[i].size()==1)
			{
				sum+=prob[i]*level[i];

			}
		}
		cout<<setprecision(20)<<fixed<<sum;

	}

}
int main()
{
	solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
vector<ll> v[100005];
bool vis[100005];
ll level[100005];
set<ll> s;
void input()
{
	cin>>n;
	n--;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		s.insert(x);
		s.insert(y);
		v[x-1].push_back(y-1);
		v[y-1].push_back(x-1);
	}

}
void bfs(ll s)
{
	vis[s]=true;
	level[s]=0;
	queue<ll> q;
	q.push(s);
	ll i;
	while(!q.empty())
	{
		ll p=q.front();
		q.pop();
		for(i=0;i<=v[p].size()-1;i++)
		{
			if(vis[v[p][i]]==false)
			{
				level[v[p][i]]=level[p]+1;
				vis[v[p][i]]=true;
				q.push(v[p][i]);
			}
		}
	}

}
void solve()
{
	input();
	bfs(0);
	ll c=0;
	long double sum=0;
	for(auto x : s)
	{
		if(v[x-1].size()==1 && x!=1)
		{
			sum=sum+level[x-1];
			c++;
		}
	}
	long double p=sum/((double)c);
	cout<<setprecision(7)<<fixed<<p;
}
int main()
{
	solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
vector<ll> v[100005];
bool vis[100005];
long double d=0;
long double sum=0;
long double k=1;
ll h=0;
void input()
{
	cin>>n;
	n--;
	while(n--)
	{
		ll x,y;
		cin>>x>>y;
		v[x-1].push_back(y-1);
		v[y-1].push_back(x-1);
	}

}
void dfs(ll s)
{
	vis[s]=true;
	for(ll i=0;i<=v[s].size()-1;i++)
	{

		if(vis[v[s][i]]==false)
		{
			d+=1;
			if(h==0)
			{
				k++;
			}
			h=1;
			dfs(v[s][i]);
		}
		else if(h==1)
		{
			sum+=d;
			d--;
			h=2;
		}
		else if(h==1)
		{

			d--;
		}

	}
}
void solve()
{
	input();
	dfs(0);
	cout<<setprecision(20)<<fixed<<(sum/k);

}
int main()
{
	solve();
}


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ld n,c;
vector<ld> sp,vis,nn,vist;
priority_queue<ld,vector<ld>,greater<ld> >pq;
queue<ld> q;
vector<ll> G[10000000];
void BFS_SP(ld i)
{vis[i]=1;
 for(auto it=G[i].begin();it!=G[i].end();++it)
     {if(vis[*it]==0)
       {if(sp[(*it)]>sp[i]+1)
        {sp[(*it)]=sp[i]+1;}
        pq.push(*it);
       }
     }
}
void NN(ld i)
{vist[i]=1;
 c=0;
 for(auto it=G[i].begin();it!=G[i].end();++it)
     {if(vist[*it]==0)
        {c++;
         q.push(*it);
         }
     }
 for(auto it=G[i].begin();it!=G[i].end();++it)
     {if(vist[*it]==0)
        {nn[*it]=c*nn[i];
         }
     }
 }

int main()
  {ios;
   ld x,y,final=0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[x].pb(y);
       G[y].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {ld s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {ld w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
       {final+=sp[i]/nn[i];}
     cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ld n,c;
ld final;
vector<ld> sp,vis,nn,vist;
priority_queue<ld,vector<ld>,greater<ld> >pq;
queue<ld> q;
vector<ld> G[100001];
void BFS_SP(ld i)
{vis[static_cast<int>(i)]=1;
 for(auto it:G[static_cast<int>(i)])
     {if(vis[static_cast<int>(it)]==0)
       {if(sp[static_cast<int>(it)]>sp[static_cast<int>(i)]+1)
        {sp[static_cast<int>(it)]=sp[static_cast<int>(i)]+1;}
        pq.push(it);
       }
     }
}
void NN(ld i)
{vist[static_cast<int>(i)]=1;
 c=0;
 for(auto it:G[static_cast<int>(i)])
     {if(vist[static_cast<int>(it)]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[static_cast<int>(i)])
     {if(vist[static_cast<int>(it)]==0)
        {nn[static_cast<int>(it)]=c*nn[static_cast<int>(i)];
         sp[static_cast<int>(i)]=0;
         }
     }
 }

int main()
  {ios;
   ld x,y,
    final=0.0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[static_cast<int>(x)].pb(y);
       G[static_cast<int>(y)].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {ld s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {ld w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
     {final=final+sp[i]/nn[i];}

    cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int n,c;
double final;
vector<int> sp,vis,nn,vist;
priority_queue<int,vector<int>,greater<int> >pq;
queue<int> q;
vector<int> G[100001];
void BFS_SP(int i)
{vis[i]=1;
 for(auto it:G[i])
     {if(vis[it]==0)
       {if(sp[(it)]>sp[i]+1)
        {sp[(it)]=sp[i]+1;}
        pq.push(it);
       }
     }
}
void NN(int i)
{vist[i]=1;
 c=0;
 for(auto it:G[i])
     {if(vist[it]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[i])
     {if(vist[it]==0)
        {nn[it]=c*nn[i];
         sp[i]=0;
         }
     }
 }

int main()
  {ios;
   int x,y,
    final=0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[x].pb(y);
       G[y].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {int s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {int w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
     {final+=static_cast<double>sp[i]/nn[i];}

    cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ld n,c;
ld final;
vector<ld> sp,vis,nn,vist;
priority_queue<ld,vector<ld>,greater<ld> >pq;
queue<ld> q;
vector<ld> G[100001];
void BFS_SP(ld i)
{vis[static_cast<int>(i)]=1;
 for(auto it:G[static_cast<int>(i)])
     {if(vis[static_cast<int>(it)]==0)
       {if(sp[static_cast<int>(it)]>sp[static_cast<int>(i)]+1)
        {sp[static_cast<int>(it)]=sp[static_cast<int>(i)]+1;}
        pq.push(it);
       }
     }
}
void NN(ld i)
{vist[static_cast<int>(i)]=1;
 c=0;
 for(auto it:G[static_cast<int>(i)])
     {if(vist[static_cast<int>(it)]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[static_cast<int>(i)])
     {if(vist[static_cast<int>(it)]==0)
        {nn[static_cast<int>(it)]=c*nn[static_cast<int>(i)];
         sp[static_cast<int>(i)]=0;
         }
     }
 }

int main()
  {ios;
   ld x,y,
    final=0.0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[static_cast<int>(x)].pb(y);
       G[static_cast<int>(y)].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {ld s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {ld w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
     {final=final+sp[i]/nn[i];}

    cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ld n,c;
vector<ld> sp,vis,nn,vist;
priority_queue<ld,vector<ld>,greater<ld> >pq;
queue<ld> q;
vector<ld> G[10000000];
void BFS_SP(ld i)
{vis[i]=1;
 for(auto it=G[i].begin();it!=G[i].end();++it)
     {if(vis[*it]==0)
       {if(sp[(*it)]>sp[i]+1)
        {sp[(*it)]=sp[i]+1;}
        pq.push(*it);
       }
     }
}
void NN(ld i)
{vist[i]=1;
 c=0;
 for(auto it=G[i].begin();it!=G[i].end();++it)
     {if(vist[*it]==0)
        {c++;
         q.push(*it);
         }
     }
 for(auto it=G[i].begin();it!=G[i].end();++it)
     {if(vist[*it]==0)
        {nn[*it]=c*nn[i];
         }
     }
 }

int main()
  {ios;
   ld x,y,final=0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[x].pb(y);
       G[y].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {ld s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {ld w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
       {final+=sp[i]/nn[i];}
     cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int n,c;
double final;
vector<int> sp,vis,nn,vist;
priority_queue<int,vector<int>,greater<int> >pq;
queue<int> q;
vector<int> G[100001];
void BFS_SP(int i)
{vis[i]=1;
 for(auto it:G[i])
     {if(vis[it]==0)
       {if(sp[(it)]>sp[i]+1)
        {sp[(it)]=sp[i]+1;}
        pq.push(it);
       }
     }
}
void NN(int i)
{vist[i]=1;
 c=0;
 for(auto it:G[i])
     {if(vist[it]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[i])
     {if(vist[it]==0)
        {nn[it]=c*nn[i];
         sp[i]=0;
         }
     }
 }

int main()
  {ios;
   int x,y,
    final=0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[x].pb(y);
       G[y].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {int s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {int w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
     {final+=static_cast<double>(sp[i])/nn[i];}

    cout<<final;

  return 0;
 }


//#include<bits/stdc++.h>
 #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int n,c;
double final;
vector<int> sp,vis,nn,vist;
priority_queue<int,vector<int>,greater<int> >pq;
queue<int> q;
vector<int> G[100001];
void BFS_SP(int i)
{vis[i]=1;
 for(auto it:G[i])
     {if(vis[it]==0)
       {if(sp[(it)]>sp[i]+1)
        {sp[(it)]=sp[i]+1;}
        pq.push(it);
       }
     }
}
void NN(int i)
{vist[i]=1;
 c=0;
 for(auto it:G[i])
     {if(vist[it]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[i])
     {if(vist[it]==0)
        {nn[it]=c*nn[i];
         sp[i]=0;
         }
     }
 }

int main()
  {ios;
   int x,y,
    final=0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[x].pb(y);
       G[y].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {int s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {int w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
     {final+=static_cast<double>sp[i]/nn[i];}

    cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll n,c;
ld final;
vector<ll> sp,vis,nn,vist;
priority_queue<ll,vector<ll>,greater<ll> >pq;
queue<ll> q;
vector<ll> G[10000000];
void BFS_SP(ll i)
{vis[i]=1;
 for(auto it:G[i])
     {if(vis[it]==0)
       {if(sp[(it)]>sp[i]+1)
        {sp[(it)]=sp[i]+1;}
        pq.push(it);
       }
     }
}
void NN(ll i)
{vist[i]=1;
 c=0;
 for(auto it:G[i])
     {if(vist[it]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[i])
     {if(vist[it]==0)
        {nn[it]=c*nn[i];
         }
     }
 }

int main()
  {ios;
   ll x,y,
    final=0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[x].pb(y);
       G[y].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {ll s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {ll w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
       {final+=(ld)sp[i]/(ld)nn[i];}
     cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ld n,c;
vector<ld> sp,vis,nn,vist;
priority_queue<ld,vector<ld>,greater<ld> >pq;
queue<ld> q;
vector<ld> G[10000000];
void BFS_SP(ld i)
{vis[i]=1;
 for(auto it:G[i])
     {if(vis[it]==0)
       {if(sp[(it)]>sp[i]+1)
        {sp[(it)]=sp[i]+1;}
        pq.push(it);
       }
     }
}
void NN(ld i)
{vist[i]=1;
 c=0;
 for(auto it:G[i])
     {if(vist[it]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[i])
     {if(vist[it]==0)
        {nn[it]=c*nn[i];
         }
     }
 }

int main()
  {ios;
   ld x,y,final=0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[x].pb(y);
       G[y].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {ld s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {ld w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
       {final+=sp[i]/nn[i];}
     cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ld n,c;
vector<ld> sp,vis,nn,vist;
priority_queue<ld,vector<ld>,greater<ld> >pq;
queue<ld> q;
void BFS_SP(ld i)
{vis[i]=1;
 for(auto it=G[i].begin();it!=G[i].end();++it)
     {if(vis[*it]==0)
       {if(sp[(*it)]>sp[i]+1)
        {sp[(*it)]=sp[i]+1;}
        pq.push(*it);
       }
     }
}
void NN(ld i)
{vist[i]=1;
 c=0;
 for(auto it=G[i].begin();it!=G[i].end();++it)
     {if(vist[*it]==0)
        {c++;
         q.push(*it);
         }
     }
 for(auto it=G[i].begin();it!=G[i].end();++it)
     {if(vist[*it]==0)
        {nn[*it]=c*nn[i];
         }
     }
 }

int main()
  {ios;
   ld x,y,final=0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[x].pb(y);
       G[y].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {ld s=pq.front();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {ld w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
       {final+=sp[i]/nn[i];}
     cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll n,c;
vector<ll> sp,vis,nn,vist;
priority_queue<ll,vector<ll>,greater<ll> >pq;
queue<ll> q;
vector<ll> G[10000000];
void BFS_SP(ll i)
{vis[i]=1;
 for(auto it:G[i])
     {if(vis[it]==0)
       {if(sp[(it)]>sp[i]+1)
        {sp[(it)]=sp[i]+1;}
        pq.push(it);
       }
     }
}
void NN(ll i)
{vist[i]=1;
 c=0;
 for(auto it:G[i])
     {if(vist[it]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[i])
     {if(vist[it]==0)
        {nn[it]=c*nn[i];
         }
     }
 }

int main()
  {ios;
   ll x,y,
    ld final=0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[x].pb(y);
       G[y].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {ll s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {ll w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
       {final+=(ld)sp[i]/(ld)nn[i];}
     cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int n,c;
double final;
vector<int> sp,vis,nn,vist;
priority_queue<int,vector<int>,greater<int> >pq;
queue<int> q;
vector<int> G[100001];
void BFS_SP(int i)
{vis[i]=1;
 for(auto it:G[i])
     {if(vis[it]==0)
       {if(sp[(it)]>sp[i]+1)
        {sp[(it)]=sp[i]+1;}
        pq.push(it);
       }
     }
}
void NN(int i)
{vist[i]=1;
 c=0;
 for(auto it:G[i])
     {if(vist[it]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[i])
     {if(vist[it]==0)
        {nn[it]=c*nn[i];
         sp[i]=0;
         }
     }
 }

int main()
  {ios;
   int x,y,
    final=0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[x].pb(y);
       G[y].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {int s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {int w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
     {final=final+static_cast<double>(sp[i])/nn[i];}

    cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
double n,c;
double final;
vector<double> sp,vis,nn,vist;
priority_queue<double,vector<double>,greater<double> >pq;
queue<double> q;
vector<double> G[100001];
void BFS_SP(double i)
{vis[static_cast<int>(i)]=1;
 for(auto it:G[static_cast<int>(i)])
     {if(vis[static_cast<int>(it)]==0)
       {if(sp[static_cast<int>(it)]>sp[static_cast<int>(i)]+1)
        {sp[static_cast<int>(it)]=sp[static_cast<int>(i)]+1;}
        pq.push(it);
       }
     }
}
void NN(double i)
{vist[static_cast<int>(i)]=1;
 c=0;
 for(auto it:G[static_cast<int>(i)])
     {if(vist[static_cast<int>(it)]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[static_cast<int>(i)])
     {if(vist[static_cast<int>(it)]==0)
        {nn[static_cast<int>(it)]=c*nn[static_cast<int>(i)];
         sp[static_cast<int>(i)]=0;
         }
     }
 }

int main()
  {ios;
   double x,y,
    final=0.0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[static_cast<int>(x)].pb(y);
       G[static_cast<int>(y)].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {double s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {double w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
     {final=final+sp[i]/nn[i];}

    cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ld n,c;
ld final;
vector<ld> sp,vis,nn,vist;
priority_queue<ld,vector<ld>,greater<ld> >pq;
queue<ld> q;
vector<ld> G[100001];
void BFS_SP(ld i)
{vis[static_cast<int>(i)]=1;
 for(auto it:G[static_cast<int>(i)])
     {if(vis[static_cast<int>(it)]==0)
       {if(sp[static_cast<int>(it)]>sp[static_cast<int>(i)]+1)
        {sp[static_cast<int>(it)]=sp[static_cast<int>(i)]+1;}
        pq.push(it);
       }
     }
}
void NN(ld i)
{vist[static_cast<int>(i)]=1;
 c=0;
 for(auto it:G[static_cast<int>(i)])
     {if(vist[static_cast<int>(it)]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[static_cast<int>(i)])
     {if(vist[static_cast<int>(it)]==0)
        {nn[static_cast<int>(it)]=c*nn[static_cast<int>(i)];
         sp[static_cast<int>(i)]=0;
         }
     }
 }

int main()
  {ios;
   ld x,y,
    final=0.0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[static_cast<int>(x)].pb(y);
       G[static_cast<int>(y)].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {ld s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {ld w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
     {final=final+sp[i]/nn[i];}

    cout<<setprecision(10)<<final;

  return 0;
 }


#include<bits/stdc++.h>
// #include</Users/arav/Downloads/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int n,c;
double final;
vector<int> sp,vis,nn,vist;
priority_queue<int,vector<int>,greater<int> >pq;
queue<int> q;
vector<int> G[100001];
void BFS_SP(int i)
{vis[i]=1;
 for(auto it:G[i])
     {if(vis[it]==0)
       {if(sp[(it)]>sp[i]+1)
        {sp[(it)]=sp[i]+1;}
        pq.push(it);
       }
     }
}
void NN(int i)
{vist[i]=1;
 c=0;
 for(auto it:G[i])
     {if(vist[it]==0)
        {c++;
         q.push(it);
         }
     }
 for(auto it:G[i])
     {if(vist[it]==0)
        {nn[it]=c*nn[i];
         sp[i]=0;
         }
     }
 }

int main()
  {ios;
   int x,y,
    final=0.0;
   cin>>n;
   sp.resize(n+1);
   vis.resize(n+1);
   nn.resize(n+1);
   vist.resize(n+1);
   rep(i,0,n+1)
{sp[i]=9999999;
 nn[i]=1;}
    sp[1]=0;
   rep(i,0,n-1)
      {cin>>x>>y;
       G[x].pb(y);
       G[y].pb(x);
      }
    pq.push(1);
    while(!pq.empty())
      {int s=pq.top();
        pq.pop();
        BFS_SP(s);}
    q.push(1);
     while(!q.empty())
       {int w=q.front();
        q.pop();
        NN(w);
       }
     rep(i,1,n+1)
     {final=final+static_cast<double>(sp[i])/nn[i];}

    cout<<final;

  return 0;
 }


#include<bits/stdc++.h>
using namespace std;
const int N =1e6+5;
#define ll           long long
#define Fill(a,b)    memset(a,b,sizeof a)

int dist[N];
int vis[N];

vector<pair <int,int> >nod[N];

void dijkstra(int s) {

    priority_queue< pair <int,int> >pq;

    for(int i=0; i<=N; i++) {
        vis[i]=0,dist[i]= INT_MAX;
    }

    pq.push({0,s});
    vis[s]=1;
    dist[s]=0;

    while(!pq.empty()) {

        int u = pq.top().second;
        vis[u]=1;
        pq.pop();

        for(int i=0; i<(int)nod[u].size(); i++) {
            int p = nod[u][i].first;
            int q = nod[u][i].second;

            if(dist[p]>dist[u]+q) {
                dist[p]=dist[u]+q;
                if(!vis[p])
                    pq.push({-1*dist[p],p});
            }
        }
    }
}
int main() {
    int u,v,w,i,j,n,m;
    scanf("%d",&n);
    if(n==1)
        return puts("0.0000000"),0;
    for(i=1; i<n; i++) {
        int l,r;
        scanf("%d%d",&l,&r);
        nod[l].push_back({r,1});
        nod[r].push_back({l,1});
    }
    dijkstra(1);
    ll sum=0;
    int cnt=0;
    for(int i=2; i<=n; i++) {
        if(nod[i].size()==1) {
            sum+=1LL*dist[i];
            cnt++;
        }
    }
    //cerr<<sum<< " " <<cnt<<endl;
    printf("%.10f\n",(double)((1.0*sum)/(1.0*cnt)));
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+6;
bool vis[N];
vector<int>g[N];
int dis[N];
int cnt,sum;
void BFS(int s) {
    queue<int>q;
    q.push(s);
    dis[s]=0;
    vis[s]=true;
    while(!q.empty()) {
        int u=q.front();
        q.pop();
        if(g[u].size()==1) {
            cnt++;
            sum+=dis[u];
        }
        for(auto v : g[u]) {
            if(!vis[v]) {
                dis[v]=dis[u]+1;
                q.push(v);
                vis[v]=true;
            }
        }
    }
}
int main() {
    int n,m;
    int i;
    scanf("%d",&n);
    if(n==1)return puts("0.0"),0;
    for(i=1; i<n; i++) {
        int l,r;
        scanf("%d%d",&l,&r);
        g[l].push_back(r);
        g[r].push_back(l);
    }
    BFS(1);
    printf("%.10f\n",(double)((1.0*sum)/(1.0*cnt)));
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+6;
bool vis[N];
vector<int>g[N];
int dis[N];
int cnt,sum;
void BFS(int s) {
    queue<int>q;
    q.push(s);
    dis[s]=0;
    vis[s]=true;
    while(!q.empty()) {
        int u=q.front();
        q.pop();
        if(g[u].size()==1) {
            cnt++;
            sum+=dis[u];
        }
        for(auto v : g[u]) {
            if(!vis[v]) {
                dis[v]=dis[u]+1;
                q.push(v);
                vis[v]=true;
            }
        }
    }
}
int main() {
    int n,m;
    int i;
    scanf("%d",&n);
    for(i=1; i<n; i++) {
        int l,r;
        scanf("%d%d",&l,&r);
        g[l].push_back(r);
        g[r].push_back(l);
    }
    BFS(1);
    printf("%.10f\n",(double)((1.0*sum)/(1.0*cnt)));
}