Easy and hard versions are actually different problems, so we advise you to read both statements carefully.You are given a weighted rooted tree, vertex $$$1$$$ is the root of this tree.A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex $$$v$$$ is the last different from $$$v$$$ vertex on the path from the root to the vertex $$$v$$$. Children of vertex $$$v$$$ are all vertices for which $$$v$$$ is the parent. A vertex is a leaf if it has no children. The weighted tree is such a tree that each edge of this tree has some weight.The weight of the path is the sum of edges weights on this path. The weight of the path from the vertex to itself is $$$0$$$.You can make a sequence of zero or more moves. On each move, you select an edge and divide its weight by $$$2$$$ rounding down. More formally, during one move, you choose some edge $$$i$$$ and divide its weight by $$$2$$$ rounding down ($$$w_i := \left\lfloor\frac{w_i}{2}\right\rfloor$$$).Your task is to find the minimum number of moves required to make the sum of weights of paths from the root to each leaf at most $$$S$$$. In other words, if $$$w(i, j)$$$ is the weight of the path from the vertex $$$i$$$ to the vertex $$$j$$$, then you have to make $$$\sum\limits_{v \in leaves} w(root, v) \le S$$$, where $$$leaves$$$ is the list of all leaves.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$S$$$ ($$$2 \le n \le 10^5; 1 \le S \le 10^{16}$$$) — the number of vertices in the tree and the maximum possible sum of weights you have to obtain. The next $$$n-1$$$ lines describe edges of the tree. The edge $$$i$$$ is described as three integers $$$v_i$$$, $$$u_i$$$ and $$$w_i$$$ ($$$1 \le v_i, u_i \le n; 1 \le w_i \le 10^6$$$), where $$$v_i$$$ and $$$u_i$$$ are vertices the edge $$$i$$$ connects and $$$w_i$$$ is the weight of this edge. It is guaranteed that the sum of $$$n$$$ does not exceed $$$10^5$$$ ($$$\sum n \le 10^5$$$).

For each test case, print the answer: the minimum number of moves required to make the sum of weights of paths from the root to each leaf at most $$$S$$$.

object E {

  import java.io.BufferedReader
  import java.io.IOException
  import java.io.InputStreamReader
  import java.util
  import java.util.PriorityQueue
  import java.util.StringTokenizer

  var currSum = 0L

  @SuppressWarnings(Array("unchecked"))
  @throws[IOException]
  def main(args: Array[String]): Unit = {
    val file = new BufferedReader(new InputStreamReader(System.in))
    var inputs = file.readLine.toInt
    while ( {
      {
        inputs -= 1; inputs + 1
      } > 0
    }) {
      var st = new StringTokenizer(file.readLine)
      val n = st.nextToken.toInt
      val s = st.nextToken.toLong
      val con = new Array[util.ArrayList[Array[Int]]](n)
      for (i <- 0 until n) {
        con(i) = new util.ArrayList[Array[Int]]
      }
      for (i <- 0 until n - 1) {
        st = new StringTokenizer(file.readLine)
        val a = st.nextToken.toInt - 1
        val b = st.nextToken.toInt - 1
        val weight = st.nextToken.toInt
        con(a).add(Array[Int](b, weight))
        con(b).add(Array[Int](a, weight))
      }
      val edges = new PriorityQueue[Array[Long]]((x: Array[Long], y: Array[Long]) => {
        def foo(x: Array[Long], y: Array[Long]) = if ((x(0) + 1) / 2 * x(1) < (y(0) + 1) / 2 * y(1)) 1
        else -1

        foo(x, y)
      })
      currSum = 0
      dfs(0, new Array[Boolean](n), con, edges)
      var moves = 0
      while ( {
        currSum > s
      }) {
        moves += 1
        val curr = edges.remove()
        currSum -= (curr(0) + 1) / 2 * curr(1)
        curr(0) /= 2
        edges.add(curr)
      }
      System.out.println(moves)
    }
  }

  def dfs(curr: Int, visited: Array[Boolean], con: Array[util.ArrayList[Array[Int]]], edges: PriorityQueue[Array[Long]]): Int = {
    visited(curr) = true
    var numVisited = 0
    var size = 0
    import scala.collection.JavaConversions._
    for (i <- con(curr)) {
      if (!visited(i(0))) {
        numVisited += 1
        val s = dfs(i(0), visited, con, edges)
        currSum += i(1).toLong * s
        edges.add(Array[Long](i(1), s))
        size += s
      }
    }
    if (numVisited == 0) return 1
    size
  }
}

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.PriorityQueue
import java.util.StringTokenizer

object WeightsDivision1399E1 {

  def main(args: Array[String]): Unit = {
    val file = new BufferedReader(new InputStreamReader(System.in))
    val inputs = file.readLine.toInt

    var i = 0
    while (i < inputs) {
      handleTC()
      i += 1
    }

    def handleTC(): Unit = {
      var st = new StringTokenizer(file.readLine)
      val v = st.nextToken.toInt
      val s = st.nextToken.toLong
      val g: Array[java.util.ArrayList[Array[Int]]] = Array.ofDim[java.util.ArrayList[Array[Int]]](v + 1)
      var inb = 0
      while (inb <= v) {
        g(inb) = new java.util.ArrayList()
        inb += 1
      }
      var ing = 1
      while (ing < v) {
        st = new StringTokenizer(file.readLine)
        val v = st.nextToken.toInt
        val u = st.nextToken.toInt
        val w = st.nextToken.toInt
        g(v).add(Array(u, w))
        g(u).add(Array(v, w))
        ing += 1
      }
      val tWs = new PriorityQueue[Array[Long]]((x: Array[Long], y: Array[Long]) => {
        def foo(x: Array[Long], y: Array[Long]) = if ((x(0) + 1) / 2 * x(1) < (y(0) + 1) / 2 * y(1)) 1
        else -1

        foo(x, y)
      })
      var cur = 0L

      // DFS
      def traverse(par: Int, p: Int = 0): Int = {
        val adjL = g(par)
        if (p != 0 && adjL.size == 1) return 1
        import scala.collection.JavaConversions._
        var sum = 0
        for (a <- adjL if a(0) != p) {
          val efs = traverse(a(0), par)
          tWs add Array(a(1), efs)
          cur += a(1) * 1L * efs
          sum += efs
        }
        sum
      }

      traverse(1)
      var ans = 0
      while (cur > s) {
        val a = tWs.remove()
        cur -= (a(0) + 1) / 2 * a(1)
        a(0) /= 2
        tWs add a
        ans += 1
      }
      println(ans)
    }
  }
}

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.PriorityQueue
import java.util.StringTokenizer

object WeightsDivision1399E1 {

  def main(args: Array[String]): Unit = {
    val file = new BufferedReader(new InputStreamReader(System.in))
    val inputs = file.readLine.toInt

    var i = 0
    while (i < inputs) {
      handleTC()
      i+=1
    }

    def handleTC(): Unit = {
      var st = new StringTokenizer(file.readLine)
      val v = st.nextToken.toInt
      val s = st.nextToken.toLong
      val g: Array[java.util.ArrayList[Array[Int]]] = Array.ofDim[java.util.ArrayList[Array[Int]]](v+1)
      var inb = 0
      while (inb <= v) {
        g(inb) = new java.util.ArrayList()
        inb+=1
      }
      var ing = 1
      while (ing < v) {
        st = new StringTokenizer(file.readLine)
        val v = st.nextToken.toInt
        val u = st.nextToken.toInt
        val w = st.nextToken.toInt
        g(v).add(Array(u,w))
        g(u).add(Array(v,w))
        ing+=1
      }
      val tWs = new PriorityQueue[Array[Long]]((x: Array[Long], y: Array[Long]) => {
        def foo(x: Array[Long], y: Array[Long]) = if ((x(0) + 1) / 2 * x(1) < (y(0) + 1) / 2 * y(1)) 1
        else -1

        foo(x, y)
      })
      var cur = 0L
      // DFS
      def traverse(par: Int, p: Int = 0): Int = {
        val adjL = g(par)
        if (p != 0 && adjL.size == 1) return 1
        import scala.collection.JavaConversions._
        var sum = 0
        for (a <- adjL if a(0) != p) {
          val efs = traverse(a(0), par)
          tWs add Array(a(1), efs)
          cur += a(1) *1L* efs
          sum += efs
        }
        sum
      }
      traverse(1)
      var ans = 0
      while (cur > s) {
        val a = tWs.remove()
        cur -= (a(0) + 1) / 2 * a(1)
        tWs add Array(a(0) / 2, a(1))
        ans += 1
      }
      println(ans)
    }
  }
}

object E {

  import java.io.BufferedReader
  import java.io.IOException
  import java.io.InputStreamReader
  import java.util
  import java.util.PriorityQueue
  import java.util.StringTokenizer

  var currSum = 0L

  @throws[IOException]
  def main(args: Array[String]): Unit = {
    val file = new BufferedReader(new InputStreamReader(System.in))
    var inputs = file.readLine.toInt
    while ( {
      {
        inputs -= 1; inputs + 1
      } > 0
    }) {
      var st = new StringTokenizer(file.readLine)
      val n = st.nextToken.toInt
      val s = st.nextToken.toLong
      val con = new Array[util.ArrayList[Array[Int]]](n)
      for (i <- 0 until n) {
        con(i) = new util.ArrayList[Array[Int]]
      }
      for (i <- 0 until n - 1) {
        st = new StringTokenizer(file.readLine)
        val a = st.nextToken.toInt - 1
        val b = st.nextToken.toInt - 1
        val weight = st.nextToken.toInt
        con(a).add(Array[Int](b, weight))
        con(b).add(Array[Int](a, weight))
      }
      val edges = new PriorityQueue[Array[Long]]((x: Array[Long], y: Array[Long]) => {
        def foo(x: Array[Long], y: Array[Long]) = if ((x(0) + 1) / 2 * x(1) < (y(0) + 1) / 2 * y(1)) 1
        else -1

        foo(x, y)
      })
      currSum = 0
      dfs(0, new Array[Boolean](n), con, edges)
      var moves = 0
      while ( {
        currSum > s
      }) {
        moves += 1
        val curr = edges.remove()
        currSum -= (curr(0) + 1) / 2 * curr(1)
        curr(0) /= 2
        edges.add(curr)
      }
      System.out.println(moves)
    }
  }

  def dfs(curr: Int, visited: Array[Boolean], con: Array[util.ArrayList[Array[Int]]], edges: PriorityQueue[Array[Long]]): Int = {
    visited(curr) = true
    var numVisited = 0
    var size = 0
    import scala.collection.JavaConversions._
    for (i <- con(curr)) {
      if (!visited(i(0))) {
        numVisited += 1
        val s = dfs(i(0), visited, con, edges)
        currSum += i(1).toLong * s
        edges.add(Array[Long](i(1), s))
        size += s
      }
    }
    if (numVisited == 0) return 1
    size
  }
}

import java.util.PriorityQueue
import java.util.StringTokenizer

import scala.io.Source

object WeightsDivision1399E1 {

  def main(args: Array[String]): Unit = {
    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines

    val inputs = lines.next.toInt
    var i = 0
    while (i < inputs) {
      handleTC()
      i+=1
    }

    def handleTC(): Unit = {
      val vAndS = lines.next.split(" ")
      val v = vAndS(0).toInt
      val s = vAndS(1).toLong
      val g: Array[java.util.ArrayList[Array[Int]]] = Array.ofDim[java.util.ArrayList[Array[Int]]](v+1)
      var inb = 0
      while (inb <= v) {
        g(inb) = new java.util.ArrayList()
        inb+=1
      }
      var ing = 1
      while (ing < v) {
        val s = lines.next.split(" ")
        val v = s(0).toInt
        val u = s(1).toInt
        val w = s(2).toInt
        g(v).add(Array(u,w))
        g(u).add(Array(v,w))
        ing+=1
      }
      val tWs = new PriorityQueue[Array[Long]]((x: Array[Long], y: Array[Long]) => {
        def foo(x: Array[Long], y: Array[Long]) = if ((x(0) + 1) / 2 * x(1) < (y(0) + 1) / 2 * y(1)) 1
        else -1

        foo(x, y)
      })
      var cur = 0L
      // DFS
      def traverse(par: Int, p: Int = 0): Int = {
        val adjL = g(par)
        if (p != 0 && adjL.size == 1) return 1
        import scala.collection.JavaConversions._
        var sum = 0
        for (a <- adjL if a(0) != p) {
          val efs = traverse(a(0), par)
          tWs add Array(a(1), efs)
          cur += a(1) *1L* efs
          sum += efs
        }
        sum
      }
      traverse(1)
      var ans = 0
      while (cur > s) {
        val a = tWs.remove()
        cur -= (a(0) + 1) / 2 * a(1)
        tWs add Array(a(0) / 2, a(1))
        ans += 1
      }
      println(ans)
    }
  }
}

//package codeforces.contests._1399

object WeightsDivisionEasy {

  import scala.collection.mutable

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(n, s) = io.StdIn.readLine.split(" ").map(_.toInt)
      val graph = Array.fill[List[(Int, Int)]](n + 1)(Nil)
      (1 until n).foreach { _ =>
        val Array(u, v, w) = io.StdIn.readLine.split(" ").map(_.toInt)
        graph(u) ::= (v, w)
        graph(v) ::= (u, w)
      }

      val leaves = new Array[Int](n + 1)

      val queue = mutable.PriorityQueue.empty[(Int, Int)](Ordering.by { case (w, c) => w * c - (w / 2) * c })

      var sum = 0

      def dfs(u: Int, p: Int): Unit = {
        if (graph(u).tail.isEmpty && graph(u).head._1 == p) leaves(u) = 1
        else
          graph(u).foreach { case (v, w) =>
            if (v != p) {
              dfs(v, u)
              leaves(u) += leaves(v)
              sum += w * leaves(v)
              queue.enqueue((w, leaves(v)))
            }
          }

      }

      dfs(1, 0)

      @scala.annotation.tailrec
      def reduce(sum: Int, steps: Int = 0): Int = {
        if (sum <= s) steps else {
          val (w, c) = queue.dequeue()
          queue.enqueue((w / 2, c))
          reduce(sum - w * c + (w / 2) * c, steps + 1)
        }
      }

      println(reduce(sum))
    }
  }
}

//package codeforces.contests._1399

object WeightsDivisionEasy {

  import scala.collection.mutable

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(n, s) = io.StdIn.readLine.split(" ").map(_.toInt)
      val graph = Array.fill[List[(Int, Int)]](n + 1)(Nil)
      (1 until n).foreach { _ =>
        val Array(u, v, w) = io.StdIn.readLine.split(" ").map(_.toInt)
        graph(u) ::= (v, w)
        graph(v) ::= (u, w)
      }

      val leaves = new Array[Int](n + 1)

      val queue = mutable.PriorityQueue.empty[(Int, Int)](Ordering.by(x => x._1 * x._2))

      var sum = 0

      def dfs(u: Int, p: Int): Unit = {
        graph(u).foreach { case (v, w) =>
          if (v != p) {
            dfs(v, u)
            leaves(u) += leaves(v)
            sum += w * leaves(v)
            queue.enqueue((w, leaves(v)))
          }
        }

        if (leaves(u) == 0) leaves(u) = 1
      }

      dfs(1, 0)

      @scala.annotation.tailrec
      def reduce(sum: Int, steps: Int = 0): Int = {
        if (sum <= s) steps else {
          val (w, c) = queue.dequeue()
          queue.enqueue((w / 2, c))
          reduce(sum - w * c + (w / 2) * c, steps + 1)
        }
      }

      println(reduce(sum))
    }
  }
}

import scala.collection.mutable
import scala.io.Source

object WeightsDivision1399E1 extends App {
    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines
//   val lines: Iterator[String] =
//     Source.fromString("1\n10 28\n8 2 8\n5 1 4\n6 1 10\n10 2 7\n7 2 1\n9 2 1\n2 1 5\n4 1 9\n3 2 5").getLines
  val ntc: Int = lines.next.toInt
  0 until ntc map { _ =>
    handleTC()
  } foreach { println }

  case class Edge(uv: (Int, Int), w: Long)

  private def handleTC() = {
    val vAndS = lines.next.split(" ")
    val v = vAndS(0).toInt
    val S = vAndS(1).toLong
    val g: Array[mutable.Set[Edge]] = Array.ofDim[mutable.Set[Edge]](v+1)
    def updEdgeSet(e: Edge, f: Edge => Int): Unit = {
      val es = Option(g(f(e))).getOrElse(mutable.Set())
      es.+=(e)
      g(f(e)) = es
    }
    for (_ <- 1 until v) {
      val s = lines.next.split(" ")
      val e = Edge((s(0).toInt, s(1).toInt), s(2).toInt)
      updEdgeSet(e, _.uv._1)
      updEdgeSet(e, _.uv._2)
    }
    val eCounts = mutable.Map[Edge, Long]()
    val tWs = mutable.PriorityQueue[(Long, Long)]()(Ordering
      .by[(Long, Long), Long](x => Math.ceil(x._1 / 2.0).asInstanceOf[Int] * x._2))
    var r = 0L
    def traverse(par: Int): Unit = {
      val adjL = g(par)
      for (e <- adjL) {
        val nonPar = if (e.uv._1 == par) e.uv._2 else e.uv._1
        val nextAdjL = g(nonPar)
        nextAdjL.remove(e)
        traverse(nonPar)
        val ec = nextAdjL.map(eCounts).sum
        val ecf = if (ec == 0) 1 else ec
        eCounts(e) = ecf
        tWs += ((e.w, ecf))
        r = r + e.w * ecf
      }
    }
    traverse(1)
    if (r <= S) {
      0
    } else {
      var st = 0
      do {
        val (w, c) = tWs.dequeue
        st = st + 1
        val ceil = Math.ceil(w / 2.0).asInstanceOf[Long]
        r = r - ceil * c
        tWs += ((Math.floor(w / 2.0).asInstanceOf[Long], c))
      } while (tWs.nonEmpty && r > S)
      st
    }
  }
}

import scala.io.Source

object WeightsDivision1399E1 {

  def main(args: Array[String]): Unit = {
//    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines
       val lines: Iterator[String] =
         Source.fromString("1\n10 28\n8 2 8\n5 1 4\n6 1 10\n10 2 7\n7 2 1\n9 2 1\n2 1 5\n4 1 9\n3 2 5").getLines

    //       1
    //   / /  \     \
    // 5   6  4      2
    //           /  / \  \ \
    //          10  8  7 9  3
    val ntc: Int = lines.next.toInt
    var i = 0
    while (i < ntc) {
      println(handleTC())
      i+=1
    }

    def handleTC(): Int = {
      val vAndS = lines.next.split(" ")
      val v = vAndS(0).toInt
      val S = vAndS(1).toLong
      val g: Array[java.util.ArrayList[(Int, Int)]] = Array.ofDim[java.util.ArrayList[(Int, Int)]](v+1)
      var inb = 0
      while (inb <= v) {
        g(inb) = new java.util.ArrayList()
        inb+=1
      }
      val efs = Array.ofDim[Int](v)
      val ws = Array.ofDim[Int](v)
      var ing = 1
      while (ing < v) {
        val s = lines.next.split(" ")
        val v = s(0).toInt
        val u = s(1).toInt
        val w = s(2).toInt
        g(v).add((u,ing))
        g(u).add((v,ing))
        ws(ing) = w
        ing+=1
      }
      val tWs: java.util.PriorityQueue[(Long, Int)] = new java.util.PriorityQueue[(Long, Int)]((x: (Long, Int), y: (Long, Int)) => {
        def foo(x: (Long, Int), y: (Long, Int)) = if (x._1 < y._1) 1 else -1
        foo(x, y)
      })
      def getDiff(e: Int): Long = (ws(e) - ws(e) / 2) * efs(e)
      var r = 0L
      // DFS
      def traverse(par: Int, grand: Int): Int = {
        val adjL = g(par)
        if (grand != 0 && adjL.size == 1) return 1
        import scala.collection.JavaConverters._
        (for ((v,id) <- adjL.asScala if id != grand) yield {
          efs(id) = traverse(v, id)
          tWs add ((getDiff(id), id))
          r = r + ws(id) * efs(id)
          efs(id)
        }).sum
      }
      traverse(1,0)
      var st = 0
      while (r > S) {
        val (k, e) = tWs.remove()
        st += 1
        ws(e) = ws(e) / 2
        r = r - k
        tWs add ((getDiff(e), e))
      }
      st
    }
  }
}

import scala.io.Source

object WeightsDivision1399E1 {

  def main(args: Array[String]): Unit = {
    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines
    //   val lines: Iterator[String] =
    //      Source.fromString("1\n10 28\n8 2 8\n5 1 4\n6 1 10\n10 2 7\n7 2 1\n9 2 1\n2 1 5\n4 1 9\n3 2 5").getLines

    //       1
    //   / /  \     \
    // 5   6  4      2
    //           /  / \  \ \
    //          10  8  7 9  3
    val ntc: Int = lines.next.toInt
    var i = 0
    while (i < ntc) {
      println(handleTC())
      i+=1
    }

    def handleTC(): Int = {
      val vAndS = lines.next.split(" ")
      val v = vAndS(0).toInt
      val s = vAndS(1).toLong
      val g: Array[java.util.ArrayList[(Int, Int)]] = Array.ofDim[java.util.ArrayList[(Int, Int)]](v+1)
      var inb = 0
      while (inb <= v) {
        g(inb) = new java.util.ArrayList()
        inb+=1
      }
      val efs = Array.ofDim[Int](v)
      val ws = Array.ofDim[Int](v)
      var ing = 1
      while (ing < v) {
        val s = lines.next.split(" ")
        val v = s(0).toInt
        val u = s(1).toInt
        val w = s(2).toInt
        g(v).add((u,ing))
        g(u).add((v,ing))
        ws(ing) = w
        ing+=1
      }
      val tWs: java.util.PriorityQueue[(Long, Int)] = new java.util.PriorityQueue[(Long, Int)]((x: (Long, Int), y: (Long, Int)) => {
        def foo(x: (Long, Int), y: (Long, Int)) = if (x._1 < y._1) 1 else if (x._1 == y._1 && x._2 < y._2) 1
        else -1
        foo(x, y)
      })
      def getDiff(e: Int): Long = (ws(e)*1L - ws(e) / 2) * efs(e)
      var cur = 0L
      // DFS
      def traverse(par: Int, p: Int = 0): Int = {
        val adjL = g(par)
        if (p != 0 && adjL.size == 1) return 1
        import scala.collection.JavaConverters._
        (for ((v,id) <- adjL.asScala if id != p) yield {
          efs(id) = traverse(v, id)
          tWs add ((getDiff(id), id))
          cur = cur + ws(id) * efs(id)
          efs(id)
        }).sum
      }
      traverse(1)
      var ans = 0
      while (cur > s) {
        val (k, id) = tWs.remove()
        cur -= k
        ws(id) /= 2
        tWs add ((getDiff(id), id))
        ans += 1
      }
      ans
    }
  }
}

import scala.io.Source

object WeightsDivision1399E1 {

  def main(args: Array[String]): Unit = {
    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines
    //   val lines: Iterator[String] =
    //      Source.fromString("1\n10 28\n8 2 8\n5 1 4\n6 1 10\n10 2 7\n7 2 1\n9 2 1\n2 1 5\n4 1 9\n3 2 5").getLines

    //       1
    //   / /  \     \
    // 5   6  4      2
    //           /  / \  \ \
    //          10  8  7 9  3
    val ntc: Int = lines.next.toInt
    var i = 0
    while (i < ntc) {
      println(handleTC())
      i+=1
    }

    def handleTC(): Int = {
      val vAndS = lines.next.split(" ")
      val v = vAndS(0).toInt
      val s = vAndS(1).toLong
      val g: Array[java.util.ArrayList[(Int, Int)]] = Array.ofDim[java.util.ArrayList[(Int, Int)]](v+1)
      var inb = 0
      while (inb <= v) {
        g(inb) = new java.util.ArrayList()
        inb+=1
      }
      val efs = Array.ofDim[Int](v)
      val ws = Array.ofDim[Int](v)
      var ing = 1
      while (ing < v) {
        val s = lines.next.split(" ")
        val v = s(0).toInt
        val u = s(1).toInt
        val w = s(2).toInt
        g(v).add((u,ing))
        g(u).add((v,ing))
        ws(ing) = w
        ing+=1
      }
      val tWs: java.util.PriorityQueue[(Long, Int)] = new java.util.PriorityQueue[(Long, Int)]((x: (Long, Int), y: (Long, Int)) => {
        def foo(x: (Long, Int), y: (Long, Int)) = if (x._1 < y._1) 1 else if (x._1 == y._1 && x._2 < y._2) 1
        else -1
        foo(x, y)
      })
      def getDiff(e: Int): Long = (ws(e) - ws(e) / 2) * efs(e)
      var cur = 0L
      // DFS
      def traverse(par: Int, p: Int = 0): Int = {
        val adjL = g(par)
        if (p != 0 && adjL.size == 1) return 1
        import scala.collection.JavaConverters._
        (for ((v,id) <- adjL.asScala if id != p) yield {
          efs(id) = traverse(v, id)
          tWs add ((getDiff(id), id))
          cur = cur + ws(id) * efs(id)
          efs(id)
        }).sum
      }
      traverse(1)
      var ans = 0
      while (cur > s) {
        val (k, id) = tWs.remove()
        cur -= k
        ws(id) /= 2
        tWs add ((getDiff(id), id))
        ans += 1
      }
      ans
    }
  }
}

import scala.collection.mutable
import scala.io.Source

object WeightsDivision1399E1 extends App {
    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines
//   val lines: Iterator[String] =
//     Source.fromString("1\n10 28\n8 2 8\n5 1 4\n6 1 10\n10 2 7\n7 2 1\n9 2 1\n2 1 5\n4 1 9\n3 2 5").getLines

  //       1
  //   / /  \     \
  // 5   6  4      2
  //           /  / \  \ \
  //          10  8  7 9  3
  val ntc: Int = lines.next.toInt
  0 until ntc map { _ =>
    handleTC()
  } foreach { println }

  case class Edge(uv: (Int, Int), w: Long)

  private def handleTC(): Int = {
    val vAndS = lines.next.split(" ")
    val v = vAndS(0).toInt
    val S = vAndS(1).toLong
    val g: Array[mutable.Set[(Int, Int)]] = Array.ofDim[mutable.Set[(Int, Int)]](v+1)
    def updEdgeSet(v: Int, u: Int, w: Int): Unit = {
      val es = Option(g(v)).getOrElse(mutable.Set())
      es.+=((u,w))
      g(v) = es
    }
    for (_ <- 1 until v) {
      val s = lines.next.split(" ")
      val v = s(0).toInt
      val u = s(1).toInt
      val w = s(2).toInt
      updEdgeSet(v, u, w)
      updEdgeSet(u, v, w)
    }
    val tWs = mutable.PriorityQueue[(Long, Long)]()(Ordering
      .by[(Long, Long), Long](x => Math.ceil(x._1 / 2.0).asInstanceOf[Int] * x._2))
    var r = 0L
    // DFS
    def traverse(par: Int, grand:Int): Long = {
      val adjL = g(par)
      if (adjL.size == 1) return 1
      (for ((v,w) <- adjL.toSeq if v != grand) yield {
        val nextAdjL = g(v)
//        nextAdjL.-=((par, w))//remove parent edge = mark as visited
        val ecf = traverse(v,par)
        tWs += ((w, ecf))
        r = r + w * ecf
        ecf
      }).sum
    }
    traverse(1,0)
    if (r <= S) {
      0
    } else {
      var st = 0
      do {
        val (w, c) = tWs.dequeue
        st = st + 1
        val ceil = Math.ceil(w / 2.0).asInstanceOf[Long]
        r = r - ceil * c
        tWs += ((w - ceil, c))
      } while (tWs.nonEmpty && r > S)
      st
    }
  }
}

import scala.collection.mutable
import scala.io.Source

object WeightsDivision1399E1 extends App {
    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines
//  val lines: Iterator[String] =
//    Source.fromString("3\n3 20\n2 1 8\n3 1 7\n5 50\n1 3 100\n1 5 10\n2 3 123\n5 4 55\n2 100\n1 2 409").getLines
  val ntc: Int = lines.next.toInt
  0 until ntc map { _ =>
    handleTC()
  } foreach { println }

  case class Edge(uv: (String, String), w: Int)

  private def handleTC() = {
    val vAndS = lines.next.split(" ")
    val v = vAndS(0).toInt
    val S = vAndS(1).toInt
    val g = mutable.Map[String, mutable.Set[Edge]]()
    def updEdgeSet(e: Edge, f: Edge => String): Unit = {
      val es = g.getOrElse(f(e), mutable.Set())
      es.add(e)
      g(f(e)) = es
    }
    for (_ <- 1 until v) {
      val s = lines.next.split(" ")
      val e = Edge((s(0), s(1)), s(2).toInt)
      updEdgeSet(e, _.uv._1)
      updEdgeSet(e, _.uv._2)
    }
    val eCounts = mutable.Map[Edge, Int]()
    val tWs = mutable.PriorityQueue[Int]()
    def traverse(par: String): Unit = {
      for (e <- g(par)) {
        val nonPar = e.uv.productIterator.find(_ != par).get.asInstanceOf[String]
        g(nonPar).remove(e)
        traverse(nonPar)
        val ec = g(nonPar).map(eCounts).sum
        val ecf = if (ec == 0) 1 else ec
        eCounts(e) = ecf
        tWs += e.w * ecf
      }
    }
    traverse("1")
    var r = tWs.sum
    if (r <= S) {
      0
    } else {
      var st = 0
      do {
        val i = tWs.dequeue
        st = st + 1
        val ceil = Math.ceil(i / 2.0).asInstanceOf[Int]
        r = r - ceil
        tWs += Math.floor(i / 2.0).asInstanceOf[Int]
      } while (tWs.nonEmpty && r > S)
      st
    }
  }
}

import scala.io.Source

object WeightsDivision1399E1 {

  def main(args: Array[String]): Unit = {
    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines
    //   val lines: Iterator[String] =
    //      Source.fromString("1\n10 28\n8 2 8\n5 1 4\n6 1 10\n10 2 7\n7 2 1\n9 2 1\n2 1 5\n4 1 9\n3 2 5").getLines

    //       1
    //   / /  \     \
    // 5   6  4      2
    //           /  / \  \ \
    //          10  8  7 9  3
    val ntc: Int = lines.next.toInt
    var i = 0
    while (i < ntc) {
      println(handleTC())
      i+=1
    }

    def handleTC(): Int = {
      val vAndS = lines.next.split(" ")
      val v = vAndS(0).toInt
      val s = vAndS(1).toLong
      val g: Array[java.util.ArrayList[(Int, Int)]] = Array.ofDim[java.util.ArrayList[(Int, Int)]](v+1)
      var inb = 0
      while (inb <= v) {
        g(inb) = new java.util.ArrayList()
        inb+=1
      }
      val efs = Array.ofDim[Int](v)
      val ws = Array.ofDim[Int](v)
      var ing = 1
      while (ing < v) {
        val s = lines.next.split(" ")
        val v = s(0).toInt
        val u = s(1).toInt
        val w = s(2).toInt
        g(v).add((u,ing))
        g(u).add((v,ing))
        ws(ing) = w
        ing+=1
      }
      val tWs: java.util.PriorityQueue[(Long, Int)] = new java.util.PriorityQueue[(Long, Int)]((x: (Long, Int), y: (Long, Int)) => {
        def foo(x: (Long, Int), y: (Long, Int)) = if (x._1 < y._1) 1 else if (x._1 == y._1 && x._2 < y._2) 1
        else -1
        foo(x, y)
      })
      def getDiff(e: Int): Long = ws(e)*1L*efs(e) - (ws(e) / 2L) * 1L*efs(e)
      var cur = 0L
      // DFS
      def traverse(par: Int, p: Int = 0): Int = {
        val adjL = g(par)
        if (p != 0 && adjL.size == 1) return 1
        import scala.collection.JavaConverters._
        (for ((v,id) <- adjL.asScala if id != p) yield {
          efs(id) = traverse(v, id)
          tWs add ((getDiff(id), id))
          cur = cur + ws(id) * efs(id)
          efs(id)
        }).sum
      }
      traverse(1)
      var ans = 0
      while (cur > s) {
        val (k, id) = tWs.remove()
        cur -= k
        ws(id) /= 2
        tWs add ((getDiff(id), id))
        ans += 1
      }
      ans
    }
  }
}

import scala.io.Source

object WeightsDivision1399E1 {

  def main(args: Array[String]): Unit = {
    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines
    //   val lines: Iterator[String] =
    //      Source.fromString("1\n10 28\n8 2 8\n5 1 4\n6 1 10\n10 2 7\n7 2 1\n9 2 1\n2 1 5\n4 1 9\n3 2 5").getLines

    //       1
    //   / /  \     \
    // 5   6  4      2
    //           /  / \  \ \
    //          10  8  7 9  3
    val ntc: Int = lines.next.toInt
    var i = 0
    while (i < ntc) {
      println(handleTC())
      i+=1
    }

    def handleTC(): Int = {
      val vAndS = lines.next.split(" ")
      val v = vAndS(0).toInt
      val S = vAndS(1).toLong
      val g: Array[java.util.ArrayList[(Int, Int)]] = Array.ofDim[java.util.ArrayList[(Int, Int)]](v+1)
      var inb = 0
      while (inb <= v) {
        g(inb) = new java.util.ArrayList()
        inb+=1
      }
      val efs = Array.ofDim[Int](v)
      val ws = Array.ofDim[Int](v)
      var ing = 1
      while (ing < v) {
        val s = lines.next.split(" ")
        val v = s(0).toInt
        val u = s(1).toInt
        val w = s(2).toInt
        g(v).add((u,ing))
        g(u).add((v,ing))
        ws(ing) = w
        ing+=1
      }
      val tWs: java.util.PriorityQueue[(Long, Int)] = new java.util.PriorityQueue[(Long, Int)]((x: (Long, Int), y: (Long, Int)) => {
        def foo(x: (Long, Int), y: (Long, Int)) = if (x._1 < y._1) 1 else -1
        foo(x, y)
      })
      def getDiff(e: Int): Long = (ws(e) - ws(e) / 2) * efs(e)
      var r = 0L
      // DFS
      def traverse(par: Int, p: Int): Int = {
        val adjL = g(par)
        if (adjL.size == 1) return 1
        import scala.collection.JavaConverters._
        (for ((v,id) <- adjL.asScala if id != p) yield {
          efs(id) = traverse(v, id)
          tWs add ((getDiff(id), id))
          r = r + ws(id) * efs(id)
          efs(id)
        }).sum
      }
      traverse(1,0)
      var st = 0
      while (r > S) {
        val (k, e) = tWs.remove()
        st += 1
        ws(e) = ws(e) / 2
        r = r - k
        tWs add ((getDiff(e), e))
      }
      st
    }
  }
}

import scala.collection.mutable
import scala.io.Source

object WeightsDivision1399E1 extends App {
//    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines
  val lines: Iterator[String] =
    Source.fromString("1\n10 28\n8 2 8\n5 1 4\n6 1 10\n10 2 7\n7 2 1\n9 2 1\n2 1 5\n4 1 9\n3 2 5").getLines

  //       1
  //   / /  \     \
  // 5   6  4      2
  //           /  / \  \ \
  //          10  8  7 9  3
  val ntc: Int = lines.next.toInt
  0 until ntc map { _ =>
    handleTC()
  } foreach { println }

  case class Edge(uv: (Int, Int), w: Long)

  private def handleTC(): Int = {
    val vAndS = lines.next.split(" ")
    val v = vAndS(0).toInt
    val S = vAndS(1).toLong
    val g: Array[mutable.Buffer[(Int, Int)]] = Array.ofDim[mutable.Buffer[(Int, Int)]](v+1)
    def updEdgeSet(v: Int, u: Int, w: Int): Unit = {
      val es = Option(g(v)).getOrElse(mutable.Buffer())
      es.+=((u,w))
      g(v) = es
    }
    for (_ <- 1 until v) {
      val s = lines.next.split(" ")
      val v = s(0).toInt
      val u = s(1).toInt
      val w = s(2).toInt
      updEdgeSet(v, u, w)
      updEdgeSet(u, v, w)
    }
    val tWs = mutable.TreeMap[(Long, Int), (Long, Long)]()
    var r = 0L
    def getDiff(w: Long, c: Long): Long = {
      Math.ceil(w / 2.0).asInstanceOf[Long] * c
    }
    // DFS
    def traverse(par: Int, grand: Int): Long = {
      val adjL = g(par)
      if (grand != 0 && adjL.size == 1) return 1
      (for ((v,w) <- adjL if v != grand) yield {
        val ecf = traverse(v, par)
        tWs((getDiff(w, ecf), v)) = (w, ecf)
        r = r + w * ecf
        ecf
      }).sum
    }
    traverse(1,0)
    var st = 0
    while (r > S) {
      val ((k, v), (w, c)) = tWs.last
      tWs.remove((k,v))
      st = st + 1
      val floor = Math.floor(w / 2.0).asInstanceOf[Long]
      r = r - k
      tWs((getDiff(floor, c), v)) = (floor, c)
    }
    st
  }
}

import scala.io.Source

object WeightsDivision1399E1 {

  def main(args: Array[String]): Unit = {
    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines
    //   val lines: Iterator[String] =
    //      Source.fromString("1\n10 28\n8 2 8\n5 1 4\n6 1 10\n10 2 7\n7 2 1\n9 2 1\n2 1 5\n4 1 9\n3 2 5").getLines

    //       1
    //   / /  \     \
    // 5   6  4      2
    //           /  / \  \ \
    //          10  8  7 9  3
    val ntc: Int = lines.next.toInt
    var i = 0
    while (i < ntc) {
      println(handleTC())
      i+=1
    }

    def handleTC(): Int = {
      val vAndS = lines.next.split(" ")
      val v = vAndS(0).toInt
      val S = vAndS(1).toLong
      val g: Array[java.util.ArrayList[(Int, Int)]] = Array.ofDim[java.util.ArrayList[(Int, Int)]](v+1)
      var inb = 0
      while (inb <= v) {
        g(inb) = new java.util.ArrayList()
        inb+=1
      }
      val efs = Array.ofDim[Int](v)
      val ws = Array.ofDim[Int](v)
      var ing = 1
      while (ing < v) {
        val s = lines.next.split(" ")
        val v = s(0).toInt
        val u = s(1).toInt
        val w = s(2).toInt
        g(v).add((u,ing))
        g(u).add((v,ing))
        ws(ing) = w
        ing+=1
      }
      val tWs: java.util.PriorityQueue[(Long, Int)] = new java.util.PriorityQueue[(Long, Int)]((x: (Long, Int), y: (Long, Int)) => {
        def foo(x: (Long, Int), y: (Long, Int)) = if (x._1 < y._1) 1 else -1
        foo(x, y)
      })
      def getDiff(e: Int): Long = (ws(e) - ws(e) / 2) * efs(e)
      var r = 0L
      // DFS
      def traverse(par: Int, grand: Int): Int = {
        val adjL = g(par)
        if (grand != 0 && adjL.size == 1) return 1
        import scala.collection.JavaConverters._
        (for ((v,id) <- adjL.asScala if id != grand) yield {
          efs(id) = traverse(v, id)
          tWs add ((getDiff(id), id))
          r = r + ws(id) * efs(id)
          efs(id)
        }).sum
      }
      traverse(1,0)
      var st = 0
      while (r > S) {
        val (k, e) = tWs.remove()
        st += 1
        ws(e) = ws(e) / 2
        r = r - k
        tWs add ((getDiff(e), e))
      }
      st
    }
  }
}

import scala.collection.mutable
import scala.io.Source

object WeightsDivision1399E1 extends App {
    val lines: Iterator[String] = Source.fromInputStream(System.in).getLines
//  val lines: Iterator[String] =
//    Source.fromString("1\n10 28\n8 2 8\n5 1 4\n6 1 10\n10 2 7\n7 2 1\n9 2 1\n2 1 5\n4 1 9\n3 2 5").getLines
  val ntc: Int = lines.next.toInt
  0 until ntc map { _ =>
    handleTC()
  } foreach { println }

  case class Edge(uv: (String, String), w: Int)

  private def handleTC() = {
    val vAndS = lines.next.split(" ")
    val v = vAndS(0).toInt
    val S = vAndS(1).toInt
    val g = mutable.Map[String, mutable.Set[Edge]]()
    def updEdgeSet(e: Edge, f: Edge => String): Unit = {
      val es = g.getOrElse(f(e), mutable.Set())
      es.add(e)
      g(f(e)) = es
    }
    for (_ <- 1 until v) {
      val s = lines.next.split(" ")
      val e = Edge((s(0), s(1)), s(2).toInt)
      updEdgeSet(e, _.uv._1)
      updEdgeSet(e, _.uv._2)
    }
    val eCounts = mutable.Map[Edge, Int]()
    val tWs = mutable.PriorityQueue[(Int, Int)]()(Ordering.by[(Int, Int), Int](x => Math.ceil(x._1 / 2.0).asInstanceOf[Int] * x._2))
    def traverse(par: String): Unit = {
      for (e <- g(par)) {
        val nonPar = e.uv.productIterator.find(_ != par).get.asInstanceOf[String]
        g(nonPar).remove(e)
        traverse(nonPar)
        val ec = g(nonPar).toSeq.map(eCounts).sum
        val ecf = if (ec == 0) 1 else ec
        eCounts(e) = ecf
        tWs += ((e.w, ecf))
      }
    }
    traverse("1")
    var r = tWs.map { case (w,c) => w * c }.sum
    if (r <= S) {
      0
    } else {
      var st = 0
      do {
        val (w, c) = tWs.dequeue
        st = st + 1
        val ceil = Math.ceil(w / 2.0).asInstanceOf[Int]
        r = r - ceil * c
        tWs += ((Math.floor(w / 2.0).asInstanceOf[Int], c))
      } while (tWs.nonEmpty && r > S)
      st
    }
  }
}


Let $$$s(x)$$$ be sum of digits in decimal representation of positive integer $$$x$$$. Given two integers $$$n$$$ and $$$m$$$, find some positive integers $$$a$$$ and $$$b$$$ such that   $$$s(a) \ge n$$$,  $$$s(b) \ge n$$$,  $$$s(a + b) \le m$$$.

The only line of input contain two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1129$$$).

Print two lines, one for decimal representation of $$$a$$$ and one for decimal representation of $$$b$$$. Both numbers must not contain leading zeros and must have length no more than $$$2230$$$.

NoteIn the first sample, we have $$$n = 6$$$ and $$$m = 5$$$. One valid solution is $$$a = 6$$$, $$$b = 7$$$. Indeed, we have $$$s(a) = 6 \ge n$$$ and $$$s(b) = 7 \ge n$$$, and also $$$s(a + b) = s(13) = 4 \le m$$$.

object Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, M = sc.nextInt()

    rep(800) { i =>
      out.print(i % 8 + 1)
    }
    out.println()

    rep_r(800) { i =>
      if (i == 0) out.print(2)
      else out.print(i % 8 + 1)
    }
    out.println()

  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


You are given two binary strings $$$x$$$ and $$$y$$$, which are binary representations of some two integers (let's denote these integers as $$$f(x)$$$ and $$$f(y)$$$). You can choose any integer $$$k \ge 0$$$, calculate the expression $$$s_k = f(x) + f(y) \cdot 2^k$$$ and write the binary representation of $$$s_k$$$ in reverse order (let's denote it as $$$rev_k$$$). For example, let $$$x = 1010$$$ and $$$y = 11$$$; you've chosen $$$k = 1$$$ and, since $$$2^1 = 10_2$$$, so $$$s_k = 1010_2 + 11_2 \cdot 10_2 = 10000_2$$$ and $$$rev_k = 00001$$$.For given $$$x$$$ and $$$y$$$, you need to choose such $$$k$$$ that $$$rev_k$$$ is lexicographically minimal (read notes if you don't know what does "lexicographically" means).It's guaranteed that, with given constraints, $$$k$$$ exists and is finite.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Next $$$2T$$$ lines contain a description of queries: two lines per query. The first line contains one binary string $$$x$$$, consisting of no more than $$$10^5$$$ characters. Each character is either 0 or 1. The second line contains one binary string $$$y$$$, consisting of no more than $$$10^5$$$ characters. Each character is either 0 or 1. It's guaranteed, that $$$1 \le f(y) \le f(x)$$$ (where $$$f(x)$$$ is the integer represented by $$$x$$$, and $$$f(y)$$$ is the integer represented by $$$y$$$), both representations don't have any leading zeroes, the total length of $$$x$$$ over all queries doesn't exceed $$$10^5$$$, and the total length of $$$y$$$ over all queries doesn't exceed $$$10^5$$$.

Print $$$T$$$ integers (one per query). For each query print such $$$k$$$ that $$$rev_k$$$ is lexicographically minimal.

NoteThe first query was described in the legend.In the second query, it's optimal to choose $$$k = 3$$$. The $$$2^3 = 1000_2$$$ so $$$s_3 = 10001_2 + 110_2 \cdot 1000_2 = 10001 + 110000 = 1000001$$$ and $$$rev_3 = 1000001$$$. For example, if $$$k = 0$$$, then $$$s_0 = 10111$$$ and $$$rev_0 = 11101$$$, but $$$rev_3 = 1000001$$$ is lexicographically smaller than $$$rev_0 = 11101$$$.In the third query $$$s_0 = 10$$$ and $$$rev_0 = 01$$$. For example, $$$s_2 = 101$$$ and $$$rev_2 = 101$$$. And $$$01$$$ is lexicographically smaller than $$$101$$$.The quote from Wikipedia: "To determine which of two strings of characters comes when arranging in lexicographical order, their first letters are compared. If they differ, then the string whose first letter comes earlier in the alphabet comes before the other string. If the first letters are the same, then the second letters are compared, and so on. If a position is reached where one string has no more letters to compare while the other does, then the first (shorter) string is deemed to come first in alphabetical order."

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = next()
    def ns(n: Int): Array[Char] = ns().toCharArray
    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }
    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }
    def nal(n: Int): Array[Long] = map(n)(_ => nl())
    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }
  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from) { i =>
      f(i)
    }
  }
  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }
  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 1000000007

  def solve(): Unit = {
    REP(ni()) { _ =>
      val X, Y = ns().reverse
      val j = Y.indexWhere(_ == '1')
      val i = X.indexWhere(_ == '1', j)
      out.println(i - j)
    }
  }
}


Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

Print one integer — the number of times Kolya will have to empty the waste section.

NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val Array(n, b, d) = lines.next().split(' ').map(_.toInt)
  println(lines.next().split(' ').map(_.toInt).filter(_ <= b).foldLeft((0, 0l)) {
    case ((cleans, v), a) if a + v > d => (cleans + 1, 0)
    case ((cleans, v), a) => (cleans, v + a)
  }._1)
}

object A709 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, b, d) = readLongs(3)
    val in = readLongs(n.toInt)
    var curr = 0L
    var res = 0
    for(i <- 0 until n.toInt) {
      if(in(i) <= b)
        curr += in(i)
      if(curr > d) {
        curr = 0
        res += 1
      }
    }

    println(res)
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine;
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._, collection.Searching._

object _709A extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write, writeAll}
    val n, b, d = read[Int]
    val oranges = read[Seq, Int](n)
    var juice, ans = 0

    oranges.filter(_ <= b) foreach {orange =>
      juice += orange
      if (juice > d) {
        juice = 0
        ans += 1
      }
    }

    write(ans)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "YES" else "NO"
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }
  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]
  def memoize[A, B](f: A => B): A ==> B = map[A] using f
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any, more: Any*): this.type = {
    printer.print(obj)
    more foreach {i =>
      printer.print(' ')
      printer.print(i)
    }
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = "\n"): this.type = write(obj mkString separator)

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val Array(n, b, d) = lines.next().split(' ').map(_.toInt)
  println(lines.next().split(' ').map(_.toInt).foldLeft((0, 0l)) {
    case ((cleans, v), a) if a >= b => (cleans, v)
    case ((cleans, v), a) if a + v > d => (cleans + 1, 0l)
    case ((cleans, v), a) => (cleans, v + a)
  }._1)
}

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val Array(n, b, d) = lines.next().split(' ').map(_.toInt)
  println(lines.next().split(' ').map(_.toInt).foldLeft((0, 0)) {
    case ((cleans, v), a) if a >= b => (cleans, v)
    case ((cleans, v), a) if a + v > d => (cleans + 1, 0)
    case ((cleans, v), a) => (cleans, v + a)
  }._1)
}


You are given two integers $$$n$$$ and $$$m$$$ ($$$m < n$$$). Consider a convex regular polygon of $$$n$$$ vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length).  Examples of convex regular polygons Your task is to say if it is possible to build another convex regular polygon with $$$m$$$ vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. Each test case is given as two space-separated integers $$$n$$$ and $$$m$$$ ($$$3 \le m < n \le 100$$$) — the number of vertices in the initial polygon and the number of vertices in the polygon you want to build.

For each test case, print the answer — "YES" (without quotes), if it is possible to build another convex regular polygon with $$$m$$$ vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon and "NO" otherwise.

Note  The first test case of the example It can be shown that the answer for the second test case of the example is "NO".

object _1312A extends CodeForcesApp {
  import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._

  override def solve(io: IO) = io.repeat {
    val n, m = io.read[Int]
    io.write((n % m == 0).toEnglish.toUpperCase)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def solve(io: IO): Any
  def main(args: Array[String]): Unit = {
    val io = new IO(System.in, System.out)
    try solve(io) finally io.close()
  }
}
/****************************[Scala Collection Utils]****************************************/
object Utils {
  import scala.collection.mutable

  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]

  def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None

  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)

  implicit class GenericExtensions[A](a: A) {
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }

  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](t: C[A]) {
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]

    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)

    def toMultiSet(withDefaultZero: Boolean): Map[A, Int] = {
      val freqTable = t.groupBy(identity).mapValues(_.size)
      if (withDefaultZero) freqTable.withDefaultValue(0) else freqTable
    }
  }

  implicit class PairExtensions[A, B](p: (A, B)) {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: B =:= A): Seq[A] = Seq(p.key, ev(p.value))
  }

  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())
  }

  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](m: C[K, V]) {
    def toMutable: mutable.Map[K, V] = mutable.Map.empty[K, V] ++ m
  }

  implicit class SetExtensions[A, C[A] <: Set[A]](s: C[A]) {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }

  implicit class IterableExtensions[A, C[A] <: Seq[A]](s: C[A]) {
    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
  }

  implicit class BooleanExtensions(x: Boolean) {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "Yes" else "No"
  }

  implicit class IntExtensions(val x: Int) extends AnyVal {
    @inline def isEven = x%2 == 0
    @inline def isOdd = x%2 == 1
  }

  def desc[A](implicit order: Ordering[A]): Ordering[A] = order.reverse  //e.g. students.sortBy(_.height)(desc)

  def map[K] = new {
    def to[V](default: => V): mutable.Map[K, V] = using(_ => default)
    def using[V](f: K => V): mutable.Map[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }

  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]

  def memoize[A, B](f: A => B): A => B = map[A] using f
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    tokenizers.headOption
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[A]]): C[A] = Iterator.fill(n)(read).to[C]
  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any*): this.type = writeAll(obj)
  def writeLine(obj: Any*): this.type = {if (obj.isEmpty) printer.println() else obj.foreach(printer.println); this}
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = {printer.print(obj.mkString(separator)); this}
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  def repeat(f: => Unit): Unit = Utils.repeat(read[Int]){f; writeLine()}

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: CanBuild[A, C[A]]) : Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                                   : Read[String]       = new Read(_.next())
    implicit val int                                                      : Read[Int]          = string.map(_.toInt)
    implicit val long                                                     : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                                   : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]                        : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]               : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                                  : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}


Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.Before assembling the zebra Grisha can make the following operation $$$0$$$ or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".Determine the maximum possible length of the zebra that Grisha can produce.

The only line contains a string $$$s$$$ ($$$1 \le |s| \le 10^5$$$, where $$$|s|$$$ denotes the length of the string $$$s$$$) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.

Print a single integer — the maximum possible zebra length.

NoteIn the first example one of the possible sequence of operations is bwwwbww|bw $$$\to$$$ w|wbwwwbwb $$$\to$$$ wbwbwwwbw, that gives the answer equal to $$$5$$$.In the second example no operation can increase the answer.

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S = ns()

    var ans = 0
    var w, b = 0
    val N = S.length
    rep(2 * N) { i =>
      if (S(i % N) == 'b') {
        b = w + 1
        w = 0
        ans = max(ans, b)
      } else {
        w = b + 1
        b = 0
        ans = max(ans, w)
      }
    }

    if (ans > N) ans = N
    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

object C extends App {

  val s = readLine

  var a = 0
  if (s.head != s.last) {
    var i = 1
    a = 2
    while (i < s.length - 1 && s(i) != s(i - 1)) {
      i += 1
      a += 1
    }
    var j = s.length - 2
    while (j >= i && s(j) != s(j + 1)) {
      j -= 1
      a += 1
    }
  }

  var b = 1
  var run = 1
  for (i <- 1 until s.length) {
    if (s(i) != s(i - 1)) run += 1
    else run = 1
    if (run > b) b = run
  }

  println(a max b)
}

object C extends App {

  val s = readLine

  var a = 0
  if (s.head != s.last) {
    var i = 1
    a = 2
    while (i < s.length && s(i) != s(i - 1)) {
      i += 1
      a += 1
    }
    var j = s.length - 2
    while (j > i && s(j) != s(j + 1)) {
      j -= 1
      a += 1
    }
  }

  var b = 0
  var run = 1
  for (i <- 1 until s.length) {
    if (s(i) != s(i - 1)) run += 1
    else run = 1
    if (run > b) b = run
  }
//println(a, b)
  println(a max b)
}

object C extends App {

  val s = readLine

  var a = 0
  if (s.head != s.last) {
    var i = 1
    a = 2
    while (i < s.length - 1 && s(i) != s(i - 1)) {
      i += 1
      a += 1
    }
    var j = s.length - 2
    while (j >= i && s(j) != s(j + 1)) {
      j -= 1
      a += 1
    }
  }

  var b = 0
  var run = 1
  for (i <- 1 until s.length) {
    if (s(i) != s(i - 1)) run += 1
    else run = 1
    if (run > b) b = run
  }

  println(a max b)
}


Mikhail walks on a Cartesian plane. He starts at the point $$$(0, 0)$$$, and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point $$$(0, 0)$$$, he can go to any of the following points in one move:   $$$(1, 0)$$$;  $$$(1, 1)$$$;  $$$(0, 1)$$$;  $$$(-1, 1)$$$;  $$$(-1, 0)$$$;  $$$(-1, -1)$$$;  $$$(0, -1)$$$;  $$$(1, -1)$$$. If Mikhail goes from the point $$$(x1, y1)$$$ to the point $$$(x2, y2)$$$ in one move, and $$$x1 \ne x2$$$ and $$$y1 \ne y2$$$, then such a move is called a diagonal move.Mikhail has $$$q$$$ queries. For the $$$i$$$-th query Mikhail's target is to go to the point $$$(n_i, m_i)$$$ from the point $$$(0, 0)$$$ in exactly $$$k_i$$$ moves. Among all possible movements he want to choose one with the maximum number of diagonal moves. Your task is to find the maximum number of diagonal moves or find that it is impossible to go from the point $$$(0, 0)$$$ to the point $$$(n_i, m_i)$$$ in $$$k_i$$$ moves.Note that Mikhail can visit any point any number of times (even the destination point!).

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Then $$$q$$$ lines follow. The $$$i$$$-th of these $$$q$$$ lines contains three integers $$$n_i$$$, $$$m_i$$$ and $$$k_i$$$ ($$$1 \le n_i, m_i, k_i \le 10^{18}$$$) — $$$x$$$-coordinate of the destination point of the query, $$$y$$$-coordinate of the destination point of the query and the number of moves in the query, correspondingly.

Print $$$q$$$ integers. The $$$i$$$-th integer should be equal to -1 if Mikhail cannot go from the point $$$(0, 0)$$$ to the point $$$(n_i, m_i)$$$ in exactly $$$k_i$$$ moves described above. Otherwise the $$$i$$$-th integer should be equal to the the maximum number of diagonal moves among all possible movements.

NoteOne of the possible answers to the first test case: $$$(0, 0) \to (1, 0) \to (1, 1) \to (2, 2)$$$.One of the possible answers to the second test case: $$$(0, 0) \to (0, 1) \to (1, 2) \to (0, 3) \to (1, 4) \to (2, 3) \to (3, 2) \to (4, 3)$$$.In the third test case Mikhail cannot reach the point $$$(10, 1)$$$ in 9 moves.

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    REP(ni()) { _ =>
      val n, m, k = nl()
      val ans = if (n > k || m > k) -1
      else {
        val par = (k - n) % 2 + (k - m) % 2
        k - par
      }
      out.println(ans)
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
import java.io._
import java.util.Scanner

import collection.mutable.HashMap
import scala.collection.{SortedSet, mutable}
import scala.util.Random
  protected val EPS = 1e-11

  private def default = (
    new StreamTokenizer(new InputStreamReader(System.in)),
    new Scanner(System.in),
    new PrintWriter(System.out)
  )

  val (in, ins, out) = {
    try {
      if (sys.props.contains("xDx")) {
        (
          new StreamTokenizer(new FileReader("input.txt")),
          new Scanner(new FileReader("input.txt")),
          new PrintWriter(new FileWriter("output.txt"))
        )
      } else {
        default
      }
    } catch {
      case _: Throwable => default
    }
  }

  private def nextInt = {
    in.nextToken
    in.nval.toInt
  }

  private def nextLong = {
    in.nextToken
    in.nval.toLong
  }

  private def nextDouble = {
    in.nextToken
    in.nval
  }

  private def nextString = {
    in.nextToken
    in.sval
  }

  private def nextChar = {
    in.nextToken
    in.ttype.toChar
  }

  def main(args: Array[String]): Unit = {
    try {
      new Run().run()
    } catch {
      case e: Throwable =>
        throw new RuntimeException(e)
    } finally out.close()
  }

  class Run {
    import collection.breakOut
    def run(): Unit = {
        val q = ins.nextInt
        for(_ <- 1 to q) {
            val n = ins.nextLong
            val m = ins.nextLong
            val k = ins.nextLong
            val max = math.max(n, m)
            if(max > k) {
                println(-1)
            } else {
                val rest = k - max
                var res = k
                val con1 = (m - n).abs % 2 == 1
                val con2 = rest % 2 == 1
                if(con1) {
                    res -= 1
                } else if(con2) {
                    res -= 2
                }

                println(res)
            }
        }
    }

  }

}

object Main {
import java.io._
import java.util.Scanner

import collection.mutable.HashMap
import scala.collection.{SortedSet, mutable}
import scala.util.Random
  protected val EPS = 1e-11

  private def default = (
    new StreamTokenizer(new InputStreamReader(System.in)),
    new Scanner(System.in),
    new PrintWriter(System.out)
  )

  val (in, ins, out) = {
    try {
      if (sys.props.contains("xDx")) {
        (
          new StreamTokenizer(new FileReader("input.txt")),
          new Scanner(new FileReader("input.txt")),
          new PrintWriter(new FileWriter("output.txt"))
        )
      } else {
        default
      }
    } catch {
      case _: Throwable => default
    }
  }

  private def nextInt = {
    in.nextToken
    in.nval.toInt
  }

  private def nextLong = {
    in.nextToken
    in.nval.toLong
  }

  private def nextDouble = {
    in.nextToken
    in.nval
  }

  private def nextString = {
    in.nextToken
    in.sval
  }

  private def nextChar = {
    in.nextToken
    in.ttype.toChar
  }

  def main(args: Array[String]): Unit = {
    try {
      new Run().run()
    } catch {
      case e: Throwable =>
        throw new RuntimeException(e)
    } finally out.close()
  }

  class Run {
    import collection.breakOut
    def run(): Unit = {
        val q = ins.nextInt
        for(_ <- 1 to q) {
            val n = ins.nextLong
            val m = ins.nextLong
            val k = ins.nextLong
            val max = math.max(n, m)
            if(max > k) {
                println(-1)
            } else {
                val rest = k - max
                var res = max + ((rest >> 1) << 1)
                if((m - n).abs % 2 == 1 || rest % 2 == 1) {
                    res -= 1
                }

                println(res)
            }
        }
    }

  }

}

object Main {
import java.io._
import java.util.Scanner

import collection.mutable.HashMap
import scala.collection.{SortedSet, mutable}
import scala.util.Random
  protected val EPS = 1e-11

  private def default = (
    new StreamTokenizer(new InputStreamReader(System.in)),
    new Scanner(System.in),
    new PrintWriter(System.out)
  )

  val (in, ins, out) = {
    try {
      if (sys.props.contains("xDx")) {
        (
          new StreamTokenizer(new FileReader("input.txt")),
          new Scanner(new FileReader("input.txt")),
          new PrintWriter(new FileWriter("output.txt"))
        )
      } else {
        default
      }
    } catch {
      case _: Throwable => default
    }
  }

  private def nextInt = {
    in.nextToken
    in.nval.toInt
  }

  private def nextLong = {
    in.nextToken
    in.nval.toLong
  }

  private def nextDouble = {
    in.nextToken
    in.nval
  }

  private def nextString = {
    in.nextToken
    in.sval
  }

  private def nextChar = {
    in.nextToken
    in.ttype.toChar
  }

  def main(args: Array[String]): Unit = {
    try {
      new Run().run()
    } catch {
      case e: Throwable =>
        throw new RuntimeException(e)
    } finally out.close()
  }

  class Run {
    import collection.breakOut
    def run(): Unit = {
        val q = ins.nextInt
        for(_ <- 1 to q) {
            val n = ins.nextLong
            val m = ins.nextLong
            val k = ins.nextLong
            val max = math.max(n, m)
            if(max > k) {
                println(-1)
            } else {
                val rest = k - max
                val min = math.min(n, m)
                var res = min - (rest % 2) + (rest / 2) * 2
                val rest2 = k - (max + (max - min))
                if(rest2 >= 0) {
                    res = math.max(res, max - (rest2 % 2) + (rest2 / 2) * 2)
                }

                println(res)
            }
        }
    }

  }

}


You are given one integer number $$$n$$$. Find three distinct integers $$$a, b, c$$$ such that $$$2 \le a, b, c$$$ and $$$a \cdot b \cdot c = n$$$ or say that it is impossible to do it.If there are several answers, you can print any.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$n$$$ lines describe test cases. The $$$i$$$-th test case is given on a new line as one integer $$$n$$$ ($$$2 \le n \le 10^9$$$).

For each test case, print the answer on it. Print "NO" if it is impossible to represent $$$n$$$ as $$$a \cdot b \cdot c$$$ for some distinct integers $$$a, b, c$$$ such that $$$2 \le a, b, c$$$. Otherwise, print "YES" and any possible such representation.

object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()
  val t = stdin.next().toInt
  println(stdin.take(t).map(_.toInt).flatMap(calc).mkString("\n"))

  def calc(x : Int): List[String] = {
    val res = split(x)
    res.size match {
        // 1
        // 1 1
        // 1 1 1
      case 1 if res.head._2 >= 6 =>
        val lh1 = res.head._1
        val nums = List(lh1, lh1 * lh1, x / (lh1 * lh1 * lh1))
        if (nums.contains(1))
          throw new Exception(s"x = ${x} ; nums = ${nums}")
        List("YES", nums.mkString(" "))
      case 2 if res.head._2 + res.last._2 >= 4 && res.head._2 > 1 && res.last._2 > 1=>
        val lh1 = res.head._1
        val lh2 = res.last._1
        val nums = List(lh1, lh2, Math.pow(res.head._1, res.head._2 - 1).toInt *  Math.pow(res.last._1, res.last._2 - 1).toInt)
        if (nums.contains(1))
          throw new Exception(s"x = ${x} ; nums = ${nums}")
        List("YES", nums.mkString(" "))
      case 2 if res.head._2 + res.last._2 >= 4 =>
        val List(a, b) = res.toList.sortBy(_._2)
        val nums = List(a._1, b._1, Math.pow(b._1, b._2 - 1).toInt)
        if (nums.contains(1))
          throw new Exception(s"x = ${x} ; nums = ${nums} ; ($a, $b)")
        List("YES", nums.mkString(" "))
      case z if z >= 3 =>
        val first = Math.pow(res.head._1, res.head._2).toInt
        val second = Math.pow(res.tail.head._1, res.tail.head._2).toInt
        val nums = List(Math.pow(res.head._1, res.head._2).toInt,
                        Math.pow(res.tail.head._1, res.tail.head._2).toInt,
          x / (first * second))
        List("YES", nums.mkString(" "))
      case _ => List("NO")
    }
  }

  def split(x: Int): Map[Int, Int] = {
    val m = Map.empty[Int, Int]
    split(x, m)
  }

  def split(x: Int, m: Map[Int, Int]): Map[Int, Int] = {
//    println(x)
    if (x == 1) m
    else {
      val f = Stream.from(2).takeWhile(y => y * y <= x).find(x % _ == 0).getOrElse(x)
//      println("f = " + x)
      split(x / f, m + (f -> (m.getOrElse(f, 0) + 1)))
    }
  }
}

//1
//6
//1 1 1 2 2 1 2 1 2 1 1 2

object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()
  val t = stdin.next().toInt
  println(stdin.take(t).map(_.toInt).flatMap(calc).mkString("\n"))

  def calc(x : Int): List[String] = {
    val res = split(x)
    res.size match {
        // 1
        // 1 1
        // 1 1 1
      case 1 if res.head._2 >= 6 =>
        val lh1 = res.head._1
        val nums = List(lh1, lh1 * lh1, x / (lh1 * lh1 * lh1))
        if (nums.contains(1))
          throw new Exception(s"x = ${x} ; nums = ${nums}")
        List("YES", nums.mkString(" "))
      case 2 if res.head._2 + res.last._2 >= 4 && res.head._2 > 1 && res.last._2 > 1=>
        val lh1 = res.head._1
        val lh2 = res.last._1
        val nums = List(lh1, lh2, Math.pow(res.head._1, res.head._2 - 1).toInt *  Math.pow(res.last._1, res.last._2 - 1).toInt)
        if (nums.contains(1))
          throw new Exception(s"x = ${x} ; nums = ${nums}")
        List("YES", nums.mkString(" "))
      case 2 if res.head._2 + res.last._2 >= 4 =>
        val List(a, b) = res.toList.sortBy(_._2)
        val nums = List(a._1, b._1, Math.pow(b._1, b._2 - 1).toInt)
        if (nums.contains(1))
          throw new Exception(s"x = ${x} ; nums = ${nums} ; ($a, $b)")
        List("YES", nums.mkString(" "))
      case z if z > 3 =>
        val first = Math.pow(res.head._1, res.head._2).toInt
        val second = Math.pow(res.tail.head._1, res.tail.head._2).toInt
        val nums = List(Math.pow(res.head._1, res.head._2).toInt,
                        Math.pow(res.tail.head._1, res.tail.head._2).toInt,
          x / (first * second))
        List("YES", nums.mkString(" "))
      case _ => List("NO")
    }
  }

  def split(x: Int): Map[Int, Int] = {
    val m = Map.empty[Int, Int]
    split(x, m)
  }

  def split(x: Int, m: Map[Int, Int]): Map[Int, Int] = {
//    println(x)
    if (x == 1) m
    else {
      val f = Stream.from(2).takeWhile(y => y * y <= x).find(x % _ == 0).getOrElse(x)
//      println("f = " + x)
      split(x / f, m + (f -> (m.getOrElse(f, 0) + 1)))
    }
  }
}

//1
//6
//1 1 1 2 2 1 2 1 2 1 1 2

object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()
  val t = stdin.next().toInt
  println(stdin.take(t).map(_.toInt).map(calc).flatten.mkString("\n"))

  def calc(x : Int): List[String] = {
    val res = split(x)
    res.size match {
        // 1
        // 1 1
        // 1 1 1
      case 1 if res.head._2 >= 6 =>
        val lh1 = res.head._1
        val nums = List(lh1, lh1 * lh1, x / (lh1 * lh1 * lh1))
        if (nums.contains(1))
          throw new Exception(s"x = ${x} ; nums = ${nums}")
        List("YES", nums.mkString(" "))
      case 2 if res.head._2 + res.last._2 >= 4 && res.head._2 > 1 && res.last._2 > 1=>
        val lh1 = res.head._1
        val lh2 = res.last._1
        val nums = List(lh1, lh2, Math.pow(res.head._1, res.head._2 - 1).toInt *  Math.pow(res.last._1, res.last._2 - 1).toInt)
        if (nums.contains(1))
          throw new Exception(s"x = ${x} ; nums = ${nums}")
        List("YES", nums.mkString(" "))
      case 2 if res.head._2 + res.last._2 >= 4 =>
        val List(a, b) = res.toList.sortBy(_._2)
        val nums = List(a._1, b._1, Math.pow(b._1, b._2 - 1).toInt)
        if (nums.contains(1))
          throw new Exception(s"x = ${x} ; nums = ${nums} ; ($a, $b)")
        List("YES", nums.mkString(" "))
      case 3 =>
        val nums = List(Math.pow(res.head._1, res.head._2).toInt,
                        Math.pow(res.tail.head._1, res.tail.head._2).toInt,
                        Math.pow(res.last._1, res.last._2).toInt)
        List("YES", nums.mkString(" "))
      case _ => List("NO")
    }
  }

  def split(x: Int): Map[Int, Int] = {
    val m = Map.empty[Int, Int]
    split(x, m)
  }

  def split(x: Int, m: Map[Int, Int]): Map[Int, Int] = {
//    println(x)
    if (x == 1) m
    else {
      val f = Stream.from(2).takeWhile(y => y * y <= x).find(x % _ == 0).getOrElse(x)
//      println("f = " + x)
      split(x / f, m + (f -> (m.getOrElse(f, 0) + 1)))
    }
  }
}

//1
//6
//1 1 1 2 2 1 2 1 2 1 1 2

object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()
  val t = stdin.next().toInt
  println(stdin.take(t).map(_.toInt).map(calc).flatten.mkString("\n"))

  def calc(x : Int): List[String] = {
    val res = split(x)
    res.size match {
        // 1
        // 1 1
        // 1 1 1
      case 1 if res.head._2 >= 6 =>
        val lh1 = res.head._1
        val nums = List(lh1, lh1 * lh1, x / (lh1 * lh1 * lh1))
        List("YES", nums.mkString(" "))
      case 2 if res.head._2 + res.last._2 >= 4 && res.head._2 > 1 && res.last._2 > 1=>
        val lh1 = res.head._1
        val lh2 = res.last._1
        val nums = List(lh1, lh2, Math.pow(res.head._1, res.head._2 - 1).toInt *  Math.pow(res.last._1, res.last._2 - 1).toInt)
        List("YES", nums.mkString(" "))
      case 2 if res.head._2 + res.last._2 >= 4 =>
        val List(a, b) = res.toList.sorted
        val nums = List(a, b._1, Math.pow(b._1, b._2 - 1).toInt)
        List("YES", nums.mkString(" "))
      case 3 =>
        val nums = List(Math.pow(res.head._1, res.head._2).toInt,
                        Math.pow(res.tail.head._1, res.tail.head._2).toInt,
                        Math.pow(res.last._1, res.last._2).toInt)
        List("YES", nums.mkString(" "))
      case _ => List("NO")
    }
  }

  def split(x: Int): Map[Int, Int] = {
    val m = Map.empty[Int, Int]
    split(x, m)
  }

  def split(x: Int, m: Map[Int, Int]): Map[Int, Int] = {
//    println(x)
    if (x == 1) m
    else {
      val f = Stream.from(2).takeWhile(y => y * y <= x).find(x % _ == 0).getOrElse(x)
//      println("f = " + x)
      split(x / f, m + (f -> (m.getOrElse(f, 0) + 1)))
    }
  }
}

//1
//6
//1 1 1 2 2 1 2 1 2 1 1 2

object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()
  val t = stdin.next().toInt
  println(stdin.take(t).map(_.toInt).map(calc).flatten.mkString("\n"))

  def calc(x : Int): List[String] = {
    val res = split(x)
    res.size match {
        // 1
        // 1 1
        // 1 1 1
      case 1 if res.head._2 >= 6 =>
        val lh1 = res.head._1
        val nums = List(lh1, lh1 * lh1, x / (lh1 * lh1 * lh1))
        List("YES", nums.mkString(" "))
      case 2 if res.head._2 + res.last._2 >= 4 && res.head._2 > 1 && res.last._2 > 1=>
        val lh1 = res.head._1
        val lh2 = res.last._1
        val nums = List(lh1, lh2, Math.pow(res.head._1, res.head._2 - 1).toInt *  Math.pow(res.last._1, res.last._2 - 1).toInt)
        List("YES", nums.mkString(" "))
      case 2 if res.head._2 + res.last._2 >= 4 =>
        val List(a, b) = res.toList.sorted
        val nums = List(a._1, b._1, Math.pow(b._1, b._2 - 1).toInt)
        List("YES", nums.mkString(" "))
      case 3 =>
        val nums = List(Math.pow(res.head._1, res.head._2).toInt,
                        Math.pow(res.tail.head._1, res.tail.head._2).toInt,
                        Math.pow(res.last._1, res.last._2).toInt)
        List("YES", nums.mkString(" "))
      case _ => List("NO")
    }
  }

  def split(x: Int): Map[Int, Int] = {
    val m = Map.empty[Int, Int]
    split(x, m)
  }

  def split(x: Int, m: Map[Int, Int]): Map[Int, Int] = {
//    println(x)
    if (x == 1) m
    else {
      val f = Stream.from(2).takeWhile(y => y * y <= x).find(x % _ == 0).getOrElse(x)
//      println("f = " + x)
      split(x / f, m + (f -> (m.getOrElse(f, 0) + 1)))
    }
  }
}

//1
//6
//1 1 1 2 2 1 2 1 2 1 1 2