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

  override def solve(io: IO) = {
    val timur = "Timur".sorted

    io.repeat {
      val (_, s) = io.read[(Int, String)]
      val ans = s.sorted == timur
      io.writeLine(ans.toEnglish)
    }
  }

  implicit class BooleanExtensions(x: Boolean) {
    def toEnglish = if (x) "YES" else "NO"
  }
}
/****************************[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 Utils]****************************************/
object Utils {
  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)

  def desc[A](implicit order: Ordering[A]): Ordering[A] = order.reverse //e.g. students.sortBy(_.height)(desc)
}
/***********************************[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)

  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
      }
    }
  }
}

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

  override def solve(io: IO) = {
    val timur = "Timur".sorted

    io.repeat {
      val (n, s) = io.read[(Int, String)]
      val ans = s.sorted == timur
      io.writeLine(ans.toEnglish)
    }
  }
}
/****************************[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)

  val charToInt: Char => Int = Character.getNumericValue
  val intToChar: Int => Char = Character.forDigit(_, 10)

  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 sumWith[B](f: A => B)(implicit n: Numeric[B]): B =
      t.foldLeft(n.zero)({case (c, x) => n.plus(c, f(x))})

    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)

  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
      }
    }
  }
}

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

  override def solve(io: IO) = {
    val timur = "Timur".sorted

    io.repeat {
      val (n, s) = io.read[(Int, String)]
      val ans = s.sorted == timur
      io.writeLine(ans.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)

  val charToInt: Char => Int = Character.getNumericValue
  val intToChar: Int => Char = Character.forDigit(_, 10)

  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 sumWith[B](f: A => B)(implicit n: Numeric[B]): B =
      t.foldLeft(n.zero)({case (c, x) => n.plus(c, f(x))})

    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)

  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
      }
    }
  }
}

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

  override def solve(io: IO) = {
    val timur = "Timur".sorted

    io.repeat {
      val (n, s) = io.read[(Int, String)]
      val ans = n == timur.length && s.sorted == timur
      io.writeLine(ans.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)

  val charToInt: Char => Int = Character.getNumericValue
  val intToChar: Int => Char = Character.forDigit(_, 10)

  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 sumWith[B](f: A => B)(implicit n: Numeric[B]): B =
      t.foldLeft(n.zero)({case (c, x) => n.plus(c, f(x))})

    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)

  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
      }
    }
  }
}

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

   override def solve(io: IO) = {
      val timur = "Timur".sorted

      io.repeat {
         val (n, s) = io.read[(Int, String)]
         val ans = n == timur.length && s.sorted == timur
         io.write(ans.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)

   val charToInt: Char => Int = Character.getNumericValue
   val intToChar: Int => Char = Character.forDigit(_, 10)

   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
         }
      }
   }
}


object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(n) = readInts(1)
  val xs, ys = Array.ofDim[Double](n)

  for (i <- 0 until n) {
    val Array(a, b) = readLongs(2)
    xs(i) = a.toDouble
    ys(i) = b.toDouble
  }

  def sqr(x: Double) = x * x

  def dist(x0: Double, y0: Double, x1: Double, y1: Double, x2: Double, y2: Double): Double = {
    Math.abs((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1) /
      Math.sqrt(sqr(y2 - y1) + sqr(x2 - x1))
  }

  def dist(x1: Double, y1: Double, x2: Double, y2: Double) = {
    Math.sqrt(sqr(y2 - y1) + sqr(x2 - x1))
  }

  def pDistance(x: Double, y: Double, x1: Double, y1: Double, x2: Double, y2: Double) = {

    var A = x - x1;
    var B = y - y1;
    var C = x2 - x1;
    var D = y2 - y1;

    var dot = A * C + B * D;
    var len_sq = C * C + D * D;
    var param = -1d;
    if (len_sq != 0) //in case of 0 length line
      param = dot / len_sq;

    var xx, yy = 0d;

    if (param < 0) {
      xx = x1;
      yy = y1;
    }
    else if (param > 1) {
      xx = x2;
      yy = y2;
    }
    else {
      xx = x1 + param * C;
      yy = y1 + param * D;
    }

    var dx = x - xx;
    var dy = y - yy;
    Math.sqrt(dx * dx + dy * dy);
  }

  var min = Double.MaxValue

  for (i <- 0 until n) {
    val d = pDistance(
      xs((i + 1) % n), ys((i + 1) % n),
      xs(i), ys(i),
      xs((i + 2) % n), ys((i + 2) % n))
    //val d2 = dist(xs(i), ys(i), xs((i + 1) % n), ys((i + 1) % n))
    //val d3 = dist(xs((i + 2) % n), ys((i + 2) % n), xs((i + 1) % n), ys((i + 1) % n))
    //val d = d1 min d2 min d3
    if (d < min) min = d
  }

  println(min / 2)
}

object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }

  val Array(n) = readInts(1)
  val xs, ys = Array.ofDim[Double](n)

  for (i <- 0 until n) {
    val Array(a, b) = readLongs(2)
    xs(i) = a.toDouble
    ys(i) = b.toDouble
  }

  def sqr(x: Double) = x * x

  def distance(x1: Double, y1: Double, x2: Double, y2: Double): Double =
    Math.sqrt(sqr(y2 - y1) + sqr(x2 - x1))

  def distPointToLineSegment(x: Double, y: Double, x1: Double, y1: Double, x2: Double, y2: Double): Double = {

    val a = x - x1
    val b = y - y1
    val c = x2 - x1
    val d = y2 - y1

    val dot = a * c + b * d
    val lengthSquared = c * c + d * d
    val param = if (lengthSquared == 0) -1 else dot / lengthSquared

    if (param < 0) distance(x, y, x1, y1)
    else if (param > 1) distance(x, y, x2, y2)
    else distance(x, y, x1 + param * c, y1 + param * d)
  }

  var min = Double.MaxValue

  for (i <- 0 until n) {
    val d = distPointToLineSegment(
      xs((i + 1) % n), ys((i + 1) % n),
      xs(i), ys(i),
      xs((i + 2) % n), ys((i + 2) % n))
    if (d < min) min = d
  }

  println(min / 2)
}

object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(n) = readInts(1)
  val xs, ys = Array.ofDim[Double](n)

  for (i <- 0 until n) {
    val Array(a, b) = readLongs(2)
    xs(i) = a.toDouble
    ys(i) = b.toDouble
  }

  def sqr(x: Double) = x * x

  def dist(x0: Double, y0: Double, x1: Double, y1: Double, x2: Double, y2: Double): Double = {
    Math.abs((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1) /
      Math.sqrt(sqr(y2 - y1) + sqr(x2 - x1))
  }

  def dist(x1: Double, y1: Double, x2: Double, y2: Double) = {
    Math.sqrt(sqr(y2 - y1) + sqr(x2 - x1))
  }

  var min = Double.MaxValue

  for (i <- 0 until n) {
    val d1 = dist(
      xs((i + 1) % n), ys((i + 1) % n),
      xs(i), ys(i),
      xs((i + 2) % n), ys((i + 2) % n))
    val d2 = dist(xs(i), ys(i), xs((i + 1) % n), ys((i + 1) % n))
    val d3 = dist(xs((i + 2) % n), ys((i + 2) % n), xs((i + 1) % n), ys((i + 1) % n))
    val d = d1 min d2 min d3
    if (d < min) min = d
  }

  println(min / 2)
}

object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(n) = readInts(1)
  val xs, ys = Array.ofDim[Double](n)

  for (i <- 0 until n) {
    val Array(a, b) = readLongs(2)
    xs(i) = a
    ys(i) = b
  }

  def sqr(x: Double) = x * x

  def dist(x0: Double, y0: Double, x1: Double, y1: Double, x2: Double, y2: Double): Double = {
    Math.abs((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1) /
      Math.sqrt(sqr(y2 - y1) + sqr(x2 - x1))
  }

  var min = Double.MaxValue

  for (i <- 0 until n) {
    val d = dist(
      xs((i + 1) % n), ys((i + 1) % n),
      xs(i), ys(i),
      xs((i + 2) % n), ys((i + 2) % n))
    if (d < min) min = d
  }

  println(min / 2)
}

object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(n) = readInts(1)
  val xs, ys = Array.ofDim[Double](n)

  for (i <- 0 until n) {
    val Array(a, b) = readLongs(2)
    xs(i) = a
    ys(i) = b
  }

  def sqr(x: Double) = x * x

  def dist(x0: Double, y0: Double, x1: Double, y1: Double, x2: Double, y2: Double): Double = {
    Math.abs((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1) /
      Math.sqrt(sqr(y2 - y1) + sqr(x2 - x1))
  }

  def dist(x1: Double, y1: Double, x2: Double, y2: Double) = {
    Math.sqrt(sqr(y2 - y1) + sqr(x2 - x1))
  }

  var min = Double.MaxValue

  for (i <- 0 to n) {
    val d1 = dist(
      xs((i + 1) % n), ys((i + 1) % n),
      xs(i % n), ys(i % n),
      xs((i + 2) % n), ys((i + 2) % n))
    val d2 = dist(xs(i % n), ys(i % n), xs((i + 1) % n), ys((i + 1) % n))
    val d3 = dist(xs((i + 2) % n), ys((i + 2) % n), xs((i + 1) % n), ys((i + 1) % n))
    val d = d1 min d2 min d3
    if (d < min) min = d
  }

  println(min / 2)
}


import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt)
  val min = data.min
  val max = data.foldLeft((0l, 0l, 0l, -1)) {
    case ((m, soFar, first, -1), el) if el == min => (0, 0, first, 0)
    case ((m, soFar, first, -1), el) => (0, 0, first + 1, -1)
    case ((m, soFar, first, _), el) if el == min => (Math.max(m, soFar), 0, first, 0)
    case ((m, soFar, first, _), el) => (Math.max(m, soFar + 1), soFar + 1, first, 0)
  }
  val maxValue = Math.max(max._1, max._3 + max._2)
  println(min.toLong * data.length + maxValue)
}

import java.util.Scanner
import scala.math._

object Main {
  def main(args: Array[String]) {
    val scanner = new Scanner(System.in)
    def next = scanner.next.toInt

    println(compute(0.until(next).map(_ => next)))
  }

  // r: a==[], many mins
  def compute(as: IndexedSeq[Int]) = {
    assert(as.size > 0)

    val minIndex = findMin(as)
    val maxBefore = countConsequentGreater(as, minIndex)
    maxBefore + as(minIndex).toLong * as.size
  }

  def findMin(as: IndexedSeq[Int]): Int = {
    var result = 0
    for (i <- 1 until as.size) {
      if (as(i) < as(result))
        result = i
    }
    result
  }

  def countConsequentGreater(as: IndexedSeq[Int], minIndex: Int) = {
    val n = as.size
    var maxBefore = 0
    var curBefore = 0

    for (i <- 0 until n) {
      val j = (minIndex - i + n) % n
      if (as(j) > as(minIndex))
        curBefore += 1
      else
        curBefore = 0
      maxBefore = max(maxBefore, curBefore)
    }

    maxBefore
  }
}

import scala.collection._

object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(n) = readInts(1)
  val as = readInts(n)
  val min = as.min.toLong

  var start = -1
  var end = -1
  var maxLen = 0
  for (i <- as.indices) {
    if (as(i) > min) {
     if (start == -1) start = i
     if (i - start + 1 > maxLen) maxLen = i - start + 1
    } else {
      start = -1
    }
  }

  var i = 0
  while (i < n && as(i) > min) i += 1
  var j = 0
  while (j < n && as(n - j - 1) > min) j += 1
  if (i + j > maxLen) maxLen = i + j

  println(min * n + maxLen)
}

import java.util.Scanner

object Main{
  def main (args: Array[String]){
    val sc = new Scanner(System.in)
    val n = sc.nextInt()

    var jar = new Array[Int](n+1)
    for(i <- 1 to n)
      jar(i) = sc.nextInt()

    // statement
    var ans = 0L

    val max = jar.max
    jar(0) = Int.MaxValue
    val min = jar.min

    // func
    def checkMinPoint(cnt: Int): List[Int] = {
      cnt > n match{
        case true  => Nil
        case false =>
          if(jar(cnt) == min)
            cnt :: checkMinPoint(cnt+1)
          else
            checkMinPoint(cnt+1)
      }
    }

    val minlist = checkMinPoint(1)

    // func
    def maxDif(list: List[Int]): Int = {
      list match{
        case _ :: Nil | Nil => 0
        case x :: y :: l2 => Math.max(y-x, maxDif(y :: l2))
      }
    }

    val tmpmax = maxDif(minlist) - 1
    val side = (n - minlist.last) + minlist(0) - 1
    val bonus = Math.max(side, tmpmax)

    if(min == max)
      println((n.toLong * jar(1)))
    else{
      println(min * n.toLong + bonus)
    }
  }

}

import scala.io.StdIn

/**
  * Created by hsleep on 2016. 1. 6..
  */
object BSolution extends App {
  val numOfJar = StdIn.readLine().toInt
  val listOfJar = StdIn.readLine().split(' ').map(_.toInt)

  val minLiter = listOfJar.min.toLong
  val indexOfEmpty = for {
    i <- 0 until numOfJar
    if listOfJar(i) == minLiter
  } yield i

  val maxDistance = indexOfEmpty.length match {
    case 1 =>
      numOfJar - 1
    case n =>
      val indexOfEmpty2 = indexOfEmpty.tail ++ Seq(numOfJar + indexOfEmpty.head)

      indexOfEmpty2.zip(indexOfEmpty).map { case (end, start) =>
        end - start - 1
      }.max
  }

  val output = minLiter * numOfJar + maxDistance
  println(output)
}

//package c610

/**
  * Created by user on 04.01.16.
  */
object B {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val colors = io.StdIn.readLine().split(" ").map(BigInt(_))

    val min = colors.min

    println(MaxLenght(n, colors))
  }

  def MaxLenght(n: Int, colors: Array[BigInt]): BigInt = {
    val minColor = colors.min

    var leftIndex = colors.lastIndexOf(minColor)
    val result = colors.zipWithIndex.filter {
      case (color, index) =>
        color == minColor
    } map {
      case (color, currentIndex) =>
        var diff = 0
        if (leftIndex > currentIndex) {
          diff = n + currentIndex - leftIndex - 1
        } else {
          if (currentIndex == leftIndex) {
            diff = n - 1
          } else {
            diff = currentIndex - leftIndex - 1
          }
        }
//        println(currentIndex + " " + color + " " + " " + diff + " " + leftIndex)
        leftIndex = currentIndex
        minColor * n + diff
    } max

    return result

//    val maxLength = colors.zipWithIndex.map {
//      case (currentColor, currentIndex) =>
//        val nextMinColorIndex = upperBound(currentIndex, minColorsIndex)
//        var diff = 0
//        if (nextMinColorIndex < currentIndex) {
//          diff = n - currentIndex + nextMinColorIndex
//        } else {
//          diff = nextMinColorIndex - currentIndex
//        }
//        val res = colors(nextMinColorIndex) * n + diff
//        res
//    }.max
//
//    maxLength
  }

  def upperBound(key: Int, xs: Array[Int]): Int = {
    val isHere = xs.find(_==key)
    if (isHere.isDefined) return key

    var len = xs.length
    var first = 0
    while (len > 0) {
      val half = len >>> 1
      val middle = first + half
      if (key < xs(middle)) {
        len = half
      } else {
        first = middle + 1
        len = len - half - 1
      }
    }
    if (first < xs.length)
      xs(first)
    else
      xs(0)
  }

}

import scala.io.StdIn

/**
  * Created by hsleep on 2016. 1. 6..
  */
object BSolution extends App {
  val numOfJar = StdIn.readLine().toInt
  val listOfJar = StdIn.readLine().split(' ').map(_.toInt)

  val minLiter = listOfJar.min
  val indexOfEmpty = for {
    i <- 0 until numOfJar
    if listOfJar(i) == minLiter
  } yield i

  val maxDistance = indexOfEmpty.length match {
    case 1 =>
      numOfJar - 1
    case n =>
      val indexOfEmpty2 = indexOfEmpty.tail ++ Seq(numOfJar - indexOfEmpty.head)

      indexOfEmpty2.zip(indexOfEmpty).map { case (start, end) =>
        start - end - 1
      }.max
  }

  val output = minLiter * numOfJar + maxDistance
  println(output)
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt)
  val min = data.min
  val max = data.foldLeft((0, 0, 0, -1)) {
    case ((m, soFar, first, -1), el) if el == min => (0, 0, first, 0)
    case ((m, soFar, first, -1), el) => (0, 0, first + 1, -1)
    case ((m, soFar, first, _), el) if el == min => (Math.max(m, soFar), 0, first, 0)
    case ((m, soFar, first, _), el) => (Math.max(m, soFar + 1), soFar + 1, first, 0)
  }
  val maxValue = Math.max(max._1, max._3 + max._2)
  println(min * data.length + maxValue)
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt)
  val min = data.min
  val max = data.foldLeft((0l, 0l, 0l, -1)) {
    case ((m, soFar, first, -1), el) if el == min => (0, 0, first, 0)
    case ((m, soFar, first, -1), el) => (0, 0, first + 1, -1)
    case ((m, soFar, first, _), el) if el == min => (Math.max(m, soFar), 0, first, 0)
    case ((m, soFar, first, _), el) => (Math.max(m, soFar + 1), soFar + 1, first, 0)
  }
  val maxValue = Math.max(max._1, max._3 + max._2)
  println(min * data.length + maxValue)
}

//package c610

/**
  * Created by user on 04.01.16.
  */
object B {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val colors = io.StdIn.readLine().split(" ").map(BigInt(_))

    val min = colors.min

    println(MaxLenght(n, colors))
  }

  def MaxLenght(n: Int, colors: Array[BigInt]): BigInt = {
    val minColor = colors.min

    var leftIndex = colors.lastIndexOf(minColor)
    val result = colors.zipWithIndex.filter {
      case (color, index) =>
        color == minColor
    } map {
      case (color, currentIndex) =>
        var diff = 0
        if (leftIndex > currentIndex) {
          diff = n + currentIndex - leftIndex - 1
        } else {
          diff = currentIndex - leftIndex - 1
        }
//        println(currentIndex + " " + color + " " + " " + diff + " " + leftIndex)
        leftIndex = currentIndex
        minColor * n + diff
    } max

    return result

//    val maxLength = colors.zipWithIndex.map {
//      case (currentColor, currentIndex) =>
//        val nextMinColorIndex = upperBound(currentIndex, minColorsIndex)
//        var diff = 0
//        if (nextMinColorIndex < currentIndex) {
//          diff = n - currentIndex + nextMinColorIndex
//        } else {
//          diff = nextMinColorIndex - currentIndex
//        }
//        val res = colors(nextMinColorIndex) * n + diff
//        res
//    }.max
//
//    maxLength
  }

  def upperBound(key: Int, xs: Array[Int]): Int = {
    val isHere = xs.find(_==key)
    if (isHere.isDefined) return key

    var len = xs.length
    var first = 0
    while (len > 0) {
      val half = len >>> 1
      val middle = first + half
      if (key < xs(middle)) {
        len = half
      } else {
        first = middle + 1
        len = len - half - 1
      }
    }
    if (first < xs.length)
      xs(first)
    else
      xs(0)
  }

}

import java.util.Scanner
import scala.math._

object Main {
  def main(args: Array[String]) {
    val scanner = new Scanner(System.in)
    def next = scanner.next.toInt

    println(compute(0.until(next).map(_ => next)))
  }

  // r: a==[], many mins
  def compute(as: IndexedSeq[Int]) = {
    assert(as.size > 0)

    val minIndex = findMin(as)
    val maxBefore = countConsequentGreater(as, minIndex)
    maxBefore + as(minIndex) * as.size
  }

  def findMin(as: IndexedSeq[Int]): Int = {
    var result = 0
    for (i <- 1 until as.size) {
      if (as(i) < as(result))
        result = i
    }
    result
  }

  def countConsequentGreater(as: IndexedSeq[Int], minIndex: Int) = {
    val n = as.size
    var maxBefore = 0
    var curBefore = 0

    for (i <- 0 until n) {
      val j = (minIndex - i + n) % n
      if (as(j) > as(minIndex))
        curBefore += 1
      else
        curBefore = 0
      maxBefore = max(maxBefore, curBefore)
    }

    maxBefore
  }
}


import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn

object Codeforces1005D {

  def getMaximumDivisibleBy3Numbers(digits: Seq[Int]): Int = {
    var previousNumbers = new ArrayBuffer[Int]
    var totalNumber = 0
    for (digit <- digits) {
      var currentReminder = digit % 3

      var index = previousNumbers.length - 1
      var found = false
      if (currentReminder == 0) {
        found = true
      }
      while (!found && index >= 0) {
        currentReminder = (currentReminder + previousNumbers(index)) % 3
        if (currentReminder == 0) found = true
        index -= 1
      }
      if (found) {
        totalNumber += 1
        previousNumbers = new ArrayBuffer[Int]
      } else {
        previousNumbers.append(digit)
      }
    }
    totalNumber
  }

  def main(args: Array[String]): Unit = {
    val digits = StdIn.readLine().map(_.toInt)
    val maximumDivisibleBy3Numbers = getMaximumDivisibleBy3Numbers(digits)
    println(maximumDivisibleBy3Numbers)
  }
}

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().map(a => (a - '0') % 3)
    val s = Array.ofDim[Boolean](3)
    var ans = 0
    import java.util

    def found(): Unit = {
      ans += 1
      util.Arrays.fill(s, false)
    }

    REP(S.length) { i =>
      S(i) match {
        case 0 => found()

        case 1 =>
          if (s(2)) {
            found()
          } else {
            s(2) = s(1)
            s(1) = true
          }

        case 2 =>
          if (s(1)) {
            found()
          } else {
            s(1) = s(2)
            s(2) = true
          }
      }
    }

    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 {
  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 A = ns().toCharArray.map(a => (a - '0') % 3)
    val N = A.length

    val last = Array.fill[Int](2, 3)(-1)
    val dp = Array.ofDim[Int](N + 1)

    REP(N) { i =>
      val x = i % 2
//      debug(s"$i ${dp.mkString}, ${last(x).mkString(",")}")

      val m = A(i)

      // まえの状態から遷移
      REP(3) { j =>
        last(x^1)((j + m) % 3) = last(x)(j)
      }
      // mの状態の最短を更新
      last(x^1)(m) = i  // 参照するのは１歩手前のDPの状態

      if (m == 0) {
        dp(i + 1) = dp(i) + 1
      } else {
        // 3をつくらない場合の個数
        dp(i + 1) = dp(i)

        if (last(x)(3 - m) != -1) {
          dp(i + 1) = max(dp(i + 1), dp(last(x)(3 - m)) + 1)
        }
      }

//      debug(s"$i ${dp.mkString}, ${last(x^1).mkString(",")}")
    }

    out.println(dp(N))
  }

  def debug(msg: String): Unit = {
    System.err.println(msg)
  }

  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[Int](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}


object A {
  import InOut._
  def main(args: Array[String]): Unit = {

    for (_ <- 1 to nextInt) {
      val n = nextInt
      val as = nextInts(n)

      for (i <- as.indices) {
        val s = if (i % 2 == 1) 1 else -1
        as(i) = math.abs(as(i)) * s
      }

      out.println(as.mkString(" "))
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}

object A extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val an = readLine().split(" ").map(_.toInt)

    val bn = an.zipWithIndex.map { case (a, i) => if (i % 2 == 0) a.abs else -a.abs }

    println(bn.mkString(" "))
  }
}

object A extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val an = readLine().split(" ").map(_.toInt)

    val bn = an.zipWithIndex.map { case (a, i) => if (i % 2 == 0) a else -a }

    println(bn.mkString(" "))
  }
}


import scala.io.StdIn

object ProblemA extends App {

  type Input = List[((String, Int, Long), (String, Int, Long))]
  def start() = {
    val input = parseInput()
    val result = input.map(solve(_))
    println(result.mkString("\n"))
  }

  def parseInput(): Input = {
    val ntc = StdIn.readLine().stripLineEnd.trim.toInt
    var result: Input = List()
    for (_ <- 0.until(ntc)) {
      val a = StdIn.readLine().stripLineEnd.trim.split(" ").map( a => (a, a.length-1))
      val b = StdIn.readLine().stripLineEnd.trim.split(" ").map( a => (a, a.length-1))
      result = ((a(0)._1, a(0)._2, a(1)._1.toLong), (b(0)._1, b(0)._2, b(1)._1.toLong) ) :: result
    }
    result.reverse
  }

  def solve(input: ((String, Int, Long), (String, Int, Long))): String = {
    val (a,b) = input

    if (a._2 < b._2) solve(( (a._1 + "0", a._2+1, a._3-1), b))
    else if (a._2 > b._2) solve(( a, (b._1 + "0", b._2+1, b._3-1)))
    else {
      if (a._3 == b._3) {
        val x = a._1.toInt
        val y = b._1.toInt
        if ( x < y) "<"
        else if (x > y) ">"
        else "="
      } else if (a._3 > b._3) {
        val x = (a._1 + "0").toInt
        val y = b._1.toInt
        if ( x < y) "<"
        else if (x > y) ">"
        else "="
      } else {
        val x = (a._1).toInt
        val y = (b._1 + "0").toInt
        if ( x < y) "<"
        else if (x > y) ">"
        else "="
      }
    }

  }

  def pow10(a: Int): Long = {
    var result = 1L
    for (_ <- 0.until(a)) result = result * 10L
    result
  }
  start()
}

import java.io._
import java.util.StringTokenizer
import scala.+:
import scala.collection.mutable
import scala.collection.mutable._
import scala.collection.immutable._
import scala.util.Sorting.quickSort
import scala.math._

object Main extends App {
    val writer =  new PrintWriter(System.out, false)
    val reader = new BufferedReader(new InputStreamReader(System.in))
    var st = new StringTokenizer("")
    def next(): String = {while (!st.hasMoreTokens) {st = new StringTokenizer(reader.readLine())};st.nextToken()}
    def readInt(): Int = next().toInt
    def readLong(): Long = next().toLong
    def readString(): String = next()

    case class fenwick(n: Int) {
        val tree = new Array[Long](n+1)
        def query(ind: Int): Long = {
            var idx = ind
            var ans = 0L
            while (idx > 0) {
                ans += tree(idx)
                idx -= (idx & -idx)
            }
            return ans
        }
        def update(ind: Int, value: Long): Unit = {
            var idx = ind
            while (idx <= n) {
                tree(idx) += value
                idx += (idx & -idx)
            }
        }
    }

    case class pair(val a: Int, val b: Int)extends Ordered[pair] {
        override def compare(that: pair): Int = {
            return -1 * a.compareTo(that.a)
        }
    }

    def gcd(a: Int, b: Int): Int = b match {
        case 0 => a
        case n => gcd(b, a % b)
    }
    val rem = 1000000007
    val maxn = 200010
    val mp = mutable.Map[Char, Int]()

    val t = readInt()

    for (tt <- 1 to t) {
        var x1 = readInt()
        val p1 = readInt()
        var x2 = readInt()
        val p2 = readInt()
        var c1 = 0
        var c2 = 0
        var tmp = x1
        while (tmp > 0) {
            c1 += 1
            tmp /= 10
        }
        tmp = x2
        while (tmp > 0) {
            c2 += 1
            tmp /= 10
        }
        if (p1 + c1 > p2 + c2) {
            writer.println('>')
        }
        if (p1 + c1 < p2 + c2) {
            writer.println('<')
        }
        if (p1 + c1 == p2 + c2){
            while (c1 < c2) {
                c1 += 1
                x1 *= 10
            }
            while (c2 < c1) {
                c2 += 1
                x2 *= 10
            }
            if (x1 < x2) {
                writer.println('<')
            }
            if (x1 > x2){
                writer.println('>')
            }
            if (x1 == x2){
                writer.println('=')
            }
        }

        def check(kk: Int): Boolean = {
            return true
        }
        def bs(st:Int, en:Int): Int = {
            if (en - st <= 1) {
                if (check(en))
                    return en
                else
                    return st
            }
            val mid = (st + en) / 2
            if (check(mid))
                return bs(mid, en)
            else
                return bs(st, mid)
        }
    }
    writer.flush()
}


object Main {
  import scala.util.control.Breaks.{breakable,break}
  import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}
  import java.io._

  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  def main (args: Array[String]){
    val q = in.next().toInt
    for (_ <- 1 to q) {
      val a, b, c = in.next().toLong
      val l = List(a, b, c).sorted
      val sum = l.sum

      val x = l(0)
      val y = l(1)
      val z = l(2)

      var ans = 0L
      if (x + z < y)
        ans = x + z
      else {
        val hoge = z - (y - x)
        ans = y + hoge / 2
      }

      pw.println(ans)
    }

    pw.flush()
  }
}
import java.io._
class InputReader(stream: InputStream) {

  import java.util.StringTokenizer

  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}

object Main extends App {
  var q: Int = readInt()
  for (_ <- 0 until q) {
    println(readLine().split("\\s").map(_.toLong).sum / 2)
  }
}

object Main extends App {
  var q: Int = readInt()
  for (_ <- 0 until q) {
    println(readLine().split("\\s+").map(_.toLong).sum / 2)
  }
}

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

  override def apply(io: IO): io.type = {
    val input = io.read[Seq[(Long, Long, Long)]]
    val ans = input.map({case (a, b, c) => (a + b + c)/2})
    io.writeLines(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()
}
/***********************************[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")

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

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

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = "\n")
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  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
      }
    }
  }
}


//package codeforces.contests._1363

object SubsequenceHate {

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val s = io.StdIn.readLine()

      val ones = {
        val arr = new Array[Int](s.length)
        arr(0) = if (s(0) == '1') 1 else 0
        (1 until s.length).foreach(i => arr(i) = (if (s(i) == '1') 1 else 0) + arr(i - 1))
        arr
      }

      def onesInRange(x: Int, y: Int): Int =
        if (x > y) 0 else if (x == 0) ones(y) else ones(y) - ones(x - 1)

      def zeroesInRange(x: Int, y: Int): Int =
        if (x > y) 0 else y - x + 1 - onesInRange(x, y)

      def makeZeroCost(x: Int, y: Int): Int = onesInRange(x, y)

      def makeOneCost(x: Int, y: Int): Int = zeroesInRange(x, y)

      val last = s.length - 1

      println {
        (0 to last).foldLeft(Int.MaxValue)((acc, i) =>
          acc min (makeOneCost(0, i) + makeZeroCost(i + 1, last)) min (makeZeroCost(0, i) + makeOneCost(i + 1, last)))
      }
    }
  }

}

import java.io._
import java.util.StringTokenizer

import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new CF646B(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final 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)(f)
  }

  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 CF646B(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val T = ni()
    REP(T) { _ =>
      val s = ns()
      val cnt0 = Array.ofDim[Int](s.length+1)
      val cnt1 = Array.ofDim[Int](s.length+1)
      cnt0(0) = 0
      cnt1(0) = 0

      s.zipWithIndex.foreach { f =>
        cnt0(f._2 + 1) = cnt0(f._2) + (if(f._1 - '0' == 0) 1 else 0)
        cnt1(f._2 + 1) = cnt1(f._2) + (if(f._1 - '0' == 1) 1 else 0)
      }
//      println(cnt0.mkString(","))
//      println(cnt1.mkString(","))
      var ans = Int.MaxValue
      REP(s.length) { i =>
        val c1 = cnt1(i+1) + (cnt0(s.length) - cnt0(i+1))
        val c0 = cnt0(i+1) + (cnt1(s.length) - cnt1(i+1))
//        println(c0 + " " + c1)
        ans = Math.min(ans, Math.min(c0, c1))
      }

      out.println(ans)
    }
  }
}

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

  override def solve(io: IO) = io.repeat {
    val a = io.read[String].toList

    def count(what: Char, left: Boolean) = {
      if (left) {
        a.scanLeft(0)({case (c, d) => if (d == what) c+1 else c})
      } else {
        a.scanRight(0)({case (d, c) => if (d == what) c+1 else c})
      }
    }.drop(1)

    val r0 = count('0', left = false)
    val l1 = count('1', left = true)
    val l0 = count('0', left = true)
    val r1 = count('1', left = false)

    val ans = (l1.zip(r0) ++ l0.zip(r1)).map({case (x, y) => x + y})

    io.write(ans.min)
  }
}
/****************************[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)

  val charToInt: Char => Int = Character.getNumericValue
  val intToChar: Int => Char = Character.forDigit(_, 10)

  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
      }
    }
  }
}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val arr = readLine().map(_ == '1').toList
      val ans = minNum(arr)
      println(ans)
    }
//          println(minNum(List[Boolean](false, false, true)))
  }

  def minNum(list: List[Boolean]): Int = {
    def zeroOne(l: List[Boolean], min: Int, left: Int, right: Int): Int = l match {
      case Nil => Math.min(min, left + right)
      case b :: bs => zeroOne(bs, Math.min(min, left + right),
        if (b) left + 1 else left, if (b) right else right - 1)
    }

    Math.min(zeroOne(list, list.count(i => !i), 0, list.count(i => !i)),
      zeroOne(list.map(i => !i), list.count(i => i), 0, list.count(i => i)))
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val arr = readLine().map(_ == '1').toList
      val ans = minNum(arr)
      println(ans)
    }
//          println(minNum(List[Boolean](false, false, true, true, false, false)))
  }

  def minNum(list: List[Boolean]): Int = {
    def zeroOne(l: List[Boolean], min: Int, left: Int, right: Int): Int = l match {
      case Nil => Math.min(min, left + right)
      case b :: bs => zeroOne(bs, Math.min(min, left + right),
        if (b) left + 1 else left, if (b) right else right + 1)
    }

    Math.min(zeroOne(list, list.count(i => i), 0, list.count(i => i)),
      zeroOne(list.map(i => !i), list.count(i => !i), 0, list.count(i => !i)))
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val arr = readLine().map(_ == '1').toList
      val ans = minNum(arr)
      println(ans)
    }
//          println(minNum(List[Boolean](false, false, true, true, false, false)))
  }

  def minNum(list: List[Boolean]): Int = {
    def zeroOne(l: List[Boolean], min: Int, left: Int, right: Int): Int = l match {
      case Nil => Math.min(min, left + right)
      case b :: bs => zeroOne(bs, Math.min(min, left + right),
        if (b) left + 1 else left, if (b) right else right + 1)
    }

    Math.min(zeroOne(list, list.count(i => !i), 0, list.count(i => !i)),
      zeroOne(list.map(i => !i), list.count(i => !i), 0, list.count(i => !i)))
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val arr = readLine().map(_ == '1').toList
      val ans = minNum(arr)
      println(ans)
    }
//          println(minNum(List[Boolean](false, false, true, true, false, false)))
  }

  def minNum(list: List[Boolean]): Int = {
    def zeroOne(l: List[Boolean], min: Int, left: Int, right: Int): Int = l match {
      case Nil => Math.min(min, left + right)
      case b :: bs => zeroOne(bs, Math.min(min, left + right),
        if (b) left + 1 else left - 1, if (b) right + 1 else right - 1)
    }

    Math.min(zeroOne(list, list.count(i => !i), 0, list.count(i => !i)),
      zeroOne(list.map(i => !i), list.count(i => !i), 0, list.count(i => !i)))
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val arr = readLine().map(_ == '1').toList
      val ans = minNum(arr)
      println(ans)
    }
//          println(minNum(List[Boolean](false, false, true, true, false, false)))
  }

  def minNum(list: List[Boolean]): Int = {
    def zeroOne(l: List[Boolean], min: Int, left: Int, right: Int): Int = l match {
      case Nil => Math.min(min, left + right)
      case b :: bs => zeroOne(bs, Math.min(min, left + right),
        if (b) left + 1 else left, if (b) right else right + 1)
    }

    Math.min(zeroOne(list, list.count(i => !i), 0, list.count(i => !i)),
      zeroOne(list.map(i => !i), list.count(i => i), 0, list.count(i => i)))
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

}


object C extends App {
  import scala.io.StdIn._

  private def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  val t = readInt()

  (0 until t).foreach { _ =>
    val n    = readInt()
    val an   = readLine().split(" ").map(_.toInt)
    val amin = an.min

    val ans = (an zip an.sorted).forall {
      case (x, y) if x == y               => true
      case (x, y) if gcd(x, amin) == amin => true
      case _                              => false
    }

    if (ans) println("YES") else println("NO")
  }
}

object C extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val an = readLine().split(" ").map(_.toInt)
    val a  = an.min

    // format: off
    val ans = (an zip an.sorted).forall {
      case (x, y) if x == y     => true
      case (x, y) if x % a == 0 => true
      case _                    => false
    }
    // format: on

    if (ans) println("YES") else println("NO")
  }
}

object C extends App {
  import scala.io.StdIn._

  private def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  val t = readInt()

  (0 until t).foreach { _ =>
    val n    = readInt()
    val an   = readLine().split(" ").map(_.toInt)
    val amin = an.min

    val ans = (an zip an.sorted).forall {
      case (x, y) if x == y               => true
      case (x, y) if gcd(x, amin) == amin => true
      case _                              => false
    }

    println(ans)
  }
}


import scala.io.StdIn._

object A extends App {
  val n = readInt()
  val B = readLine().split(" ").map(_ == "1")

  if (B.length == 1) {
    if (B.head == true) println("YES") else println("NO")
  } else {
    if (B.count(_ == false) == 1) println("YES") else println("NO")
  }

}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val buttons = in.next().count(_ == '1')
  if (buttons == 0 || (n != 1 && (n - buttons) != 1))
    println("NO")
  else
    println("YES")
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val buttons = in.next().count(_ == '1')
  if (buttons == 0 || (n - buttons) != 1)
    println("NO")
  else
    println("YES")
}