A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.Substring is a continuous subsequence of a string.

The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100 000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.

Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.

NoteIn the first sample AI's name may be replaced with "int#llect".In the second sample Gogol can just keep things as they are.In the third sample one of the new possible names of AI may be "s#ris#ri".

/**
  * Created by octavian on 07/02/2016.
  */
object War {

  def main(args: Array[String]) = {

    //System.setIn(new FileInputStream("./src/war.in"))
    //System.setOut(new PrintStream(new FileOutputStream("./src/war.out")))

    val a: Array[Char] = readLine().toCharArray
    val b: Array[Char] = readLine().toCharArray
    var matches: Vector[Int] = Vector.empty[Int]
    for(i <- 0 until a.length) {
      if(a.slice(i, i + b.length).deep == b.deep) {
        matches :+= i
      }
    }

    var lastPos = -1
    var result = 0
    for(i <- 0 until matches.length) {
      if(lastPos < matches(i)) {
        lastPos = matches(i) + b.length - 1
        result += 1
      }
    }
    println(result)
  }

}

object A {
  def main(args: Array[String]) {
    val phone = scala.io.StdIn.readLine
    val ai = scala.io.StdIn.readLine
    val counts = phone.replaceAll(ai, "#").toCharArray.groupBy(l => l)
    if (counts.isDefinedAt('#')) {
      println(counts('#').length)
    } else {
      println(0)
    }

  }
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val str1 = in.next()
  val str2 = in.next()
  val replace = str2.init + '#'
  println(str1.replaceAll(str2, replace).count(_ == '#'))
}

object Main {
  import scala.annotation.tailrec
  import java.io.{BufferedReader, PrintWriter, PrintStream, PushbackReader}
  class MyConsole(val in: BufferedReader, val _out: PrintStream,
                  val err: PrintStream) {
    // PrintWriter do not flush automatically
    val out = new PrintWriter(_out,false)
    // If argument is null, there are ambiguous which function will be called
    def print(obj: Any)                  = out.print(if(obj == null) "null" else obj.toString)
    def println()                        = out.println()
    def println(obj: Any)                = out.println(obj)
    def printf(text: String, args: Any*) = out.printf(text.format(args : _*))
    // NOTE: YOU MUST FLUSH BEFORE END OF MAIN
    def flush()                          = out.flush()
    def debugln(obj: Any)                = err.println("\u001b[36m" + obj + "\u001b[0m")

    def readIntVector()    : Vector[Int]    = parseLineToVector(() => nextInt)
    def readLongVector()   : Vector[Long]   = parseLineToVector(() => nextLong)
    def readStringVector() : Vector[String] = parseLineToVector(() => nextString)
    def nextInt()          : Int            = nextLong().toInt
    def nextBigInt()       : BigInt         = BigInt(nextString())
    def nextBigDecimal(  ) : BigDecimal     = BigDecimal(nextString())
    def nextDouble()       : Double         = nextString().toDouble
    def nextLong() : Long = {
      if(!goNextValuable())
        throw new NoSuchElementException("Reading long failed")
      val sgn = if(peek == '-') -1l else 1
      if(sgn == -1l) ignore(read())
      if(peek < '0' || '9' < peek)
        throw new NumberFormatException(s"readLong found only '-' or no number")
      @tailrec
      def readLong(next: Int, cur: Long) : Long =
        if('0' <= next && next <= '9'){
          ignore(read()) // is equal to next
          readLong(peek, cur*10 + next-'0')
        }
        else if(isEnd(next) || isSpaceOrControl(next))
          sgn*cur
        else
          throw new NumberFormatException(s"readLong found strange byte $next")
      val res = readLong(peek,0)
      skipTrailingSpaces()
      res
    }
    def nextString() : String = {
      if(!goNextValuable())
        throw new NoSuchElementException("Reading String failed")
      val builder = new StringBuilder
      @tailrec
      def appendCode(next: Int) : String = {
        if(isEnd(next) || isSpaceOrControl(next)){
          builder.toString
        }else{
          builder.append(read().toChar) // here we skip.
            appendCode(peek)
        }
      }
      val res = appendCode(peek)
      skipTrailingSpaces()
      res
    }
    // TODO: refactoring to marge nextString
    def readLine() : String = {
      if(isEnd(peek))
        throw new NoSuchElementException("Reading Line failed")
      skipNewline()
      val builder = new StringBuilder
      @tailrec
      def appendCode(next: Int) : String = {
        if(isEnd(next) || isNewLine(next)){
          builder.toString
        }else{
          builder.append(next.toChar)
          appendCode(read())
        }
      }
      appendCode(read())
    }
    // helpers
    private def ignore[T](x: => T) : Unit = { x; () }
    private[this] var peeked: Option[Int] = None
    private[this] var is_first = true
    protected def read() = {
      val res = peeked match {
        case None    => in.read()
        case Some(a) => { peeked = None; a }
      }
      is_first = false
      res
    }
    private def peek() =
      peeked match {
        case None    => {
          val res = in.read()
          peeked  = Some(res)
          res
        }
        case Some(a) => a
      }
    private def isEnd(c: Int)     = c == -1
    private def isCR(c: Int)      = c == 13
    private def isLF(c: Int)      = c == 10
    private def isNewLine(c: Int) = isLF(c) || isCR(c)
    private def isThereReadable() = !isEnd(peek)
    private def isSpaceOrControl(c: Int) = (0 <= c && c <= 32) || c == 127
    @tailrec
    final private def goNextNotSpaceNorControl() : Unit =
      if(isSpaceOrControl(peek)){
        ignore(read())
        goNextNotSpaceNorControl()
      }
    final private def skipTrailingSpaces() : Unit = {
      @tailrec
      def skipTrailingSpacesAux() : Unit = {
        if(!isNewLine(peek) && isSpaceOrControl(peek)){
          ignore(read())
          skipTrailingSpacesAux()
        }
      }
      skipTrailingSpacesAux()
    }
    final private def skipNewline() : Unit =
      if(!is_first){
        if(isCR(peek))
          ignore(read())
        if(isLF(peek))
          ignore(read())
      }
    private def goNextValuable() : Boolean = {
      goNextNotSpaceNorControl()
      isThereReadable()
    }

    private def parseLineToVector[X](parser: () => X) : Vector[X] = {
      import scala.collection.immutable.VectorBuilder
      val vb = new VectorBuilder[X]()
      skipNewline()
      @tailrec
      def parseLineToVectorAux() : Vector[X] =
        if(isNewLine(peek) || isEnd(peek)) {
          vb.result
        }else{
          vb += parser()
          parseLineToVectorAux()
        }
      parseLineToVectorAux()
    }
  }
  def main(args: Array[String]) : Unit = {
    val console = new MyConsole(Console.in, Console.out, Console.err)
    val solver  = new Solver(console)
    solver.main()
    console.flush()
  }
  class Solver(val stdio: MyConsole){
    import stdio._ // shadow Console.~
      @tailrec
    final def solve(s: String, t: String, i : Int, a: Int) : Int = {
      val k = s.indexOf(t, i)
      if(k == -1)
        a
      else
        solve(s, t, k + t.length, a+1)
    }
    def main() : Unit = {
      val s = readLine()
      val t = readLine()
      println(solve(s, t, 0, 0))
    }
  }
}

// object Main
import java.io.{IOException, InputStream, PrintWriter}
import java.util.InputMismatchException

object Main {

    def solveCase(caseNo: Int, in: InputReader, out: PrintWriter): Unit = {
        val a = in.next().toCharArray
        val b = in.next()
        var answer = 0
        for (i <- 0 until a.length) {
            if (b.zipWithIndex.forall{p => i + p._2 < a.length && p._1 == a(i + p._2)}) {
                answer += 1
                a(i + b.length - 1) = '#'
            }
        }
        out.println(answer)
    }

    def solve(in: InputReader, out: PrintWriter): Unit = {
        solveCase(1, in, out)
//        val caseCount = in.nextInt()
//        for (caseNo <- 1 to caseCount) {
//            solveCase(caseNo, in, out)
//        }
    }

    def main(args: Array[String]) {
        val in = new InputReader(System.in)
        val out = new PrintWriter(System.out)

        solve(in, out)

        in.close()
        out.close()
    }
}

class InputReader(val inputStream: InputStream) {
    val buf = new Array[Byte](1 << 16)
    var curChar = 0
    var numChars = 0

    def read(): Int = {
        if (numChars == -1) {
            throw new InputMismatchException()
        }
        if (curChar >= numChars) {
            curChar = 0
            try {
                numChars = inputStream.read(buf)
            } catch {
                case _: IOException => throw new InputMismatchException()
            }
            if (numChars <= 0)
                return -1
        }
        curChar += 1
        buf(curChar - 1)
    }

    def peek(): Int = {
        if (numChars == -1) {
            return -1
        }
        if (curChar >= numChars) {
            curChar = 0
            try {
                numChars = inputStream.read(buf)
            } catch {
                case _: IOException => return -1
            }
            if (numChars <= 0)
                return -1
        }
        buf(curChar)
    }

    def isSpaceChar(c: Int): Boolean = c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1

    def nextInt(): Int = {
        var c = read()
        while (isSpaceChar(c)) c = read()
        var sgn = 1
        if (c == '-') {
            sgn = -1
            c = read()
        }
        var res = 0
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException()
            res *= 10
            res += c & 15
            c = read()
        } while (!isSpaceChar(c))
        res * sgn
    }

    def nextLong(): Long = {
        var c = read()
        while (isSpaceChar(c)) c = read()
        var sgn = 1
        if (c == '-') {
            sgn = -1
            c = read()
        }
        var res = 0l
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException()
            res *= 10
            res += c & 15
            c = read()
        } while (!isSpaceChar(c))
        res * sgn
    }

    def next(): String = {
        var c = read()
        while (isSpaceChar(c)) c = read()
        val res = new StringBuilder()
        do {
            res += c.toChar
            c = read()
        } while (!isSpaceChar(c))
        res.toString()
    }

    def nextChar(): Char = {
        var c = read()
        while (isSpaceChar(c)) c = read()
        c.toChar
    }

    //noinspection AccessorLikeMethodIsEmptyParen
    def hasNext(): Boolean = {
        var value = peek()
        do {
            read()
            value = peek()
        } while (isSpaceChar(value) && value != -1)
        value != -1
    }

    def rawNextLine(): String = {
        val builder = new StringBuilder
        var c = read()
        while (c != '\n' && c != -1) {
            if (c != '\r')
                builder += c.toChar
            c = read()
        }
        builder.toString()
    }

    def nextLine(): String = {
        var s = rawNextLine()
        while (s.trim().length == 0) s = rawNextLine()
        s
    }

    def nextDouble(): Double = {
        next().toDouble
    }

    def close(): Unit = {
        inputStream.close()
    }
}

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

import scala.annotation.implicitNotFound
import scala.reflect.ClassTag

/**
  * Created by nimas on 2/4/16.
  */
object B extends App{

  class Template(val delim: String = " ") {

    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
    val it = Iterator.iterate(new StringTokenizer(""))(tok => if (tok.hasMoreTokens) tok else new StringTokenizer(in.readLine(), delim))

    def nextTs[T: ParseAble](n: Int)(delim: String = " ")(implicit ev: ClassTag[T]) = (Array fill n) {
      nextT[T](delim)
    }

    def nextT[T](delim: String = " ")(implicit parser: ParseAble[T]) = {
      val x = it.find(_.hasMoreTokens)
      parser parse (x get)
    }

    def close(): Unit = {
      in.close()
      out.close()
    }

    @implicitNotFound("No member of type class ParseAble in scope for ${T}")
    trait ParseAble[T] {
      def parse(strTok: StringTokenizer): T
    }

    object ParseAble {

      implicit object ParseAbleString extends ParseAble[String] {
        override def parse(strTok: StringTokenizer): String = strTok nextToken()
      }

      implicit object ParseAbleInt extends ParseAble[Int] {
        override def parse(strTok: StringTokenizer): Int = strTok nextToken() toInt
      }

      implicit object ParseAbleLong extends ParseAble[Long] {
        override def parse(strTok: StringTokenizer): Long = strTok nextToken() toLong
      }

      implicit object ParseAbleDouble extends ParseAble[Double] {
        override def parse(strTok: StringTokenizer): Double = strTok nextToken() toDouble
      }

      implicit object ParseAbleBigInt extends ParseAble[BigInt] {
        override def parse(strTok: StringTokenizer): BigInt = BigInt(strTok nextToken())
      }

    }

  }

  val io = new Template()

  import io._

  val ai = nextT[String]()
  val apple = nextT[String]()

  val s1 = apple.r findAllMatchIn ai

  out println (s1 size)

  close()

}

/**
 * @author pvasilyev
 * @since 18 Jun 2016
 */
object B625 extends App {

  def checkSubString(a: String, start: Int, b: String): Boolean = {
    if (a.length - start < b.length) {
      return false
    } else {
      for (i <- 0 until b.length) {
        if (a.charAt(start + i) != b.charAt(i)) {
          return false
        }
      }
    }
    true
  }

  def solve() = {
    val gogol: String = scala.io.StdIn.readLine()
    val pineapple: String = scala.io.StdIn.readLine()
    var answer = 0
    var i = 0
    while (i < gogol.length) {
      if (checkSubString(gogol, i, pineapple)) {
        answer += 1
        i += pineapple.length
      } else {
        i += 1
      }
    }
    println(answer)
  }

  solve()

}

import scala.io.Source

object round_342_div2_B {
    def main(args: Array[String]){
        val in = Source.stdin.getLines()
        val now = in.next() + "#"
        val old = in.next()

        println(now.split(old).length-1)
    }
}

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

object _625B extends CodeForcesApp {
  override type Result = Int

  override def solve(read: InputReader) = {
    val (t, s) = (read[String], read[String])

    @tailrec
    def f(i: Int, acc: Int): Int = t.indexOf(s, i) match {
      case p if p >= 0 => f(p + s.length, acc + 1)
      case _ => acc
    }

    f(0, 0)
  }

  override def format(result: Result) = result.toString
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  type Result
  def solve(scanner: InputReader): Result
  def format(result: Result): String
  def apply(scanner: InputReader): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new InputReader(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}
import java.util.StringTokenizer

class InputReader(reader: BufferedReader) extends Iterator[String] with AutoCloseable {
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream) = this(new InputStreamReader(inputStream))
  def this(str: String) = this(new StringReader(str))

  private[this] val tokenizers = Iterator.continually(reader.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered

  @inline private[this] def tokenizer(): Option[StringTokenizer] = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    if (tokenizers.nonEmpty) Some(tokenizers.head) else None
  }

  def apply[A: Parser]: A = implicitly[Parser[A]].apply(next())

  def tillEndOfLine(): String = tokenizer().get.nextToken("\n\r")
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

trait Parser[A] {
  def apply(s: String): A
}
object Parser {
  def apply[A](f: String => A) = new Parser[A] {
    override def apply(s: String) = f(s)
  }
  implicit val stringParser: Parser[String] = Parser(identity)
  implicit val charParser: Parser[Char] = Parser(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val booleanParser: Parser[Boolean] = Parser(_.toBoolean)
  implicit val intParser: Parser[Int] = Parser(_.toInt)
  implicit val longParser: Parser[Long] = Parser(_.toLong)
  implicit val bigIntParser: Parser[BigInt] = Parser(BigInt(_))
  implicit val doubleParser: Parser[Double] = Parser(_.toDouble)
  implicit val bigDecimalParser: Parser[BigDecimal] = Parser(BigDecimal(_))
}

/**
  * Created by Tsibin.
  */
object Problemset625 {
  def main(args: Array[String]): Unit = {
    val problem = new ProblemB
    problem.solve()
  }

  private abstract class Problem {
    val stdIn = scala.io.StdIn
    def solve()
  }

  private class ProblemA extends Problem {
    override def solve(): Unit = {
      val Array(n, a, b, c) = Iterator.continually(stdIn.readLine())
        .takeWhile(_ != null)
        .map(BigInt(_))
        .toArray
      var count = BigInt(0)

      if (n < a && n < b) {
        println(0)
        return
      }
      if (a >= b - c && n >= b) {
        count = (n - c) / (b - c)
        val remains = n - (count * (b - c))
        if (remains > 0)
          count += remains / a
      }
      else
        count = n / a
      println(count)
    }
  }

  private class ProblemB extends Problem {
    override def solve() : Unit = {
      val Array(gogolII, pineappleTel) = Iterator.continually(stdIn.readLine())
        .takeWhile(_ != null)
        .toArray
      println(pineappleTel.r.findAllIn(gogolII).length)
    }
  }
}

/**
 * @author pvasilyev
 * @since 18 Jun 2016
 */
object B625 extends App {

  def solve() = {
    val gogol: String = scala.io.StdIn.readLine()
    val pineapple: String = scala.io.StdIn.readLine()
    var answer = 0
    var j = 0
    for (i <- 0 until gogol.length) {
      if (gogol.charAt(i) == pineapple.charAt(j)) {
        j += 1
      }
      if (j == pineapple.length) {
        j = 0
        answer += 1
      }
    }
    println(answer)
  }

  solve()

}

/**
 * @author pvasilyev
 * @since 18 Jun 2016
 */
object B625 extends App {

  def checkSubString(a: String, start: Int, b: String): Boolean = {
    if (a.length - start < b.length) {
      return false
    } else {
      for (i <- 0 until b.length) {
        if (a.charAt(start + i) != b.charAt(i)) {
          return false
        }
      }
    }
    true
  }

  def solve() = {
    val gogol: String = scala.io.StdIn.readLine()
    val pineapple: String = scala.io.StdIn.readLine()
    var answer = 0
    var j = 0
    for (i <- 0 until gogol.length) {
      if (checkSubString(gogol, i, pineapple)) {
        answer += 1
      }
    }
    println(answer)
  }

  solve()

}

/**
 * @author pvasilyev
 * @since 18 Jun 2016
 */
object B625 extends App {

  def solve() = {
    val gogol: String = scala.io.StdIn.readLine()
    val pineapple: String = scala.io.StdIn.readLine()
    var answer = 0
    var j = 0
    for (i <- 0 until gogol.length) {
      if (gogol.charAt(i) == pineapple.charAt(j)) {
        j += 1
      } else if (gogol.charAt(i) == pineapple.charAt(0)) {
        j = 1
      } else {
        j = 0
      }
      if (j == pineapple.length) {
        j = 0
        answer += 1
      }
    }
    println(answer)
  }

  solve()

}


Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1, l2, ..., lm (1 ≤ li ≤ n). For each number li he wants to know how many distinct numbers are staying on the positions li, li + 1, ..., n. Formally, he want to find the number of distinct numbers among ali, ali + 1, ..., an.?Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each li.

The first line contains two integers n and m (1 ≤ n, m ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the array elements. Next m lines contain integers l1, l2, ..., lm. The i-th line contains integer li (1 ≤ li ≤ n).

Print m lines — on the i-th line print the answer to the number li.

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  val data = in.next().split(" ").map(_.toInt)
  var set = Set.empty[Int]
  val result = data.reverse.map { el =>
    set += el
    set.size
  }.reverse
  print(Range(0, m).map(_ => result(in.next().toInt - 1)).mkString("\n"))
}

import scala.collection.mutable.HashSet

object B368 {
  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.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))
  }

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    val input = readInts(n)
    val output = new Array[Int](n)
    val set = HashSet.empty[Int]
    for(i <- n-1 to 0 by -1) {
      set += input(i)
      output(i) = set.size
    }
    for(_ <- 0 until m) {
      val Array(l) = readInts(1)
      println(output(l-1))
    }
  }
}


This is an interactive problem.Omkar has just come across a duck! The duck is walking on a grid with $$$n$$$ rows and $$$n$$$ columns ($$$2 \leq n \leq 25$$$) so that the grid contains a total of $$$n^2$$$ cells. Let's denote by $$$(x, y)$$$ the cell in the $$$x$$$-th row from the top and the $$$y$$$-th column from the left. Right now, the duck is at the cell $$$(1, 1)$$$ (the cell in the top left corner) and would like to reach the cell $$$(n, n)$$$ (the cell in the bottom right corner) by moving either down $$$1$$$ cell or to the right $$$1$$$ cell each second.Since Omkar thinks ducks are fun, he wants to play a game with you based on the movement of the duck. First, for each cell $$$(x, y)$$$ in the grid, you will tell Omkar a nonnegative integer $$$a_{x,y}$$$ not exceeding $$$10^{16}$$$, and Omkar will then put $$$a_{x,y}$$$ uninteresting problems in the cell $$$(x, y)$$$. After that, the duck will start their journey from $$$(1, 1)$$$ to $$$(n, n)$$$. For each cell $$$(x, y)$$$ that the duck crosses during their journey (including the cells $$$(1, 1)$$$ and $$$(n, n)$$$), the duck will eat the $$$a_{x,y}$$$ uninteresting problems in that cell. Once the duck has completed their journey, Omkar will measure their mass to determine the total number $$$k$$$ of uninteresting problems that the duck ate on their journey, and then tell you $$$k$$$.Your challenge, given $$$k$$$, is to exactly reproduce the duck's path, i. e. to tell Omkar precisely which cells the duck crossed on their journey. To be sure of your mastery of this game, Omkar will have the duck complete $$$q$$$ different journeys ($$$1 \leq q \leq 10^3$$$). Note that all journeys are independent: at the beginning of each journey, the cell $$$(x, y)$$$ will still contain $$$a_{x,y}$$$ uninteresting tasks.

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
      case (i, j) => if (i % 2 == 0) 0L else 1L << (i + j)
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = l | u | as(i)(j)
      }
    }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (as(i)(j) == 0) {
          if (i > 0 && (as(i - 1)(j) & k) != 0) {
            i -= 1
          } else {
            j -= 1
          }
        } else {
          if (j > 0 && (as(i)(j - 1) & k) != 0) {
            j -= 1
          } else {
            i -= 1
          }
        }
      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n)(i => Array.fill(n)(1L << i))

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val min, max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = Math.max(l, u) + as(i)(j)
      }
    }
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        if (i == 0 && j == 0) {
          min(i)(j) = as(i)(j)
        } else {
          val l = if (j > 0) min(i)(j - 1) else Long.MaxValue
          val u = if (i > 0) min(i - 1)(j) else Long.MaxValue
          min(i)(j) = Math.min(l, u) + as(i)(j)
        }
      }
    }
//    for (aa <- min) {
//      out.println(aa.mkString(" "))
//      out.flush()
//    }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (j > 0 && min(i)(j - 1) <= k) {
          j -= 1
        } else {
          i -= 1
        }
//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
      if (k != as(0)(0)) {
        while (true) {
        }
      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n)(i => Array.fill(n)(1L << i))

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = Math.max(l, u) + as(i)(j)
      }
    }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j) >= k) {
          i -= 1
        } else {
          j -= 1
        }
      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
      }
      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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
      case (i, j) => (1L << (n + i - 1)) + (1L << j)
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(Set.empty[Long])
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val a = as(i)(j)
        val lu = if (i == 0 && j == 0) {
          Set(0L)
        } else {
          val l = if (j > 0) max(i)(j - 1) else Set.empty[Long]
          val u = if (i > 0) max(i - 1)(j) else Set.empty[Long]
          l | u
        }
        max(i)(j) = lu.map(_ + a)
      }
    }

//    println()
//        for (aa <- max) {
//          println(aa.mkString(" "))
//        }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j)(k)) {
          i -= 1
        } else {
          j -= 1
        }
//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
//      if (k != as(0)(0)) {
//        while (true) {
//
//        }
//      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n)(i => Array.fill(n)(1L << (2 * i)))

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = Math.max(l, u) + as(i)(j)
      }
    }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j) >= k) {
          i -= 1
        } else {
          j -= 1
        }
      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
      }
      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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
      case (i, j) => (1024L << i) - j
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(Set.empty[Long])
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val a = as(i)(j)
        val lu = if (i == 0 && j == 0) {
          Set(0L)
        } else {
          val l = if (j > 0) max(i)(j - 1) else Set.empty[Long]
          val u = if (i > 0) max(i - 1)(j) else Set.empty[Long]
          l | u
        }
        max(i)(j) = lu.map(_ + a)
      }
    }

//    println()
//        for (aa <- max) {
//          println(aa.mkString(" "))
//        }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j)(k)) {
          i -= 1
        } else {
          j -= 1
        }
//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
//      if (k != as(0)(0)) {
//        while (true) {
//
//        }
//      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n)(i => Array.fill(n)(1L << i))

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = Math.max(l, u) + as(i)(j)
      }
    }
//    for (aa <- max) {
//      out.println(aa.mkString(" "))
//      out.flush()
//    }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j) >= k) {
          i -= 1
        } else {
          j -= 1
        }
      }
      if (k != as(0)(0)) {
        throw new NoSuchElementException
      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n)(i => Array.fill(n)(1L << i))

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = Math.max(l, u) + as(i)(j)
      }
    }
//    for (aa <- max) {
//      out.println(aa.mkString(" "))
//      out.flush()
//    }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j) >= k) {
          i -= 1
        } else {
          j -= 1
        }
      }
      if (k != as(0)(0)) {
        while (true) {

        }
      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
      case (i, j) => (1L << (n + i)) + (1L << j)
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(Set.empty[Long])
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val a = as(i)(j)
        val lu = if (i == 0 && j == 0) {
          Set(0L)
        } else {
          val l = if (j > 0) max(i)(j - 1) else Set.empty[Long]
          val u = if (i > 0) max(i - 1)(j) else Set.empty[Long]
          l | u
        }
        max(i)(j) = lu.map(_ + a)
      }
    }

//    println()
//        for (aa <- max) {
//          println(aa.mkString(" "))
//        }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j)(k)) {
          i -= 1
        } else {
          j -= 1
        }
//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
//      if (k != as(0)(0)) {
//        while (true) {
//
//        }
//      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n)(i => Array.fill(n)(1L << i))

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = Math.max(l, u) + as(i)(j)
      }
    }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j) >= k) {
          i -= 1
        } else {
          j -= 1
        }
      }
      if (k != as(0)(0)) {
        throw new NoSuchElementException
      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
      }
      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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n)(i => Array.fill(n)(1L << i))

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val min, max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = Math.max(l, u) + as(i)(j)
      }
    }
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        if (i == 0 && j == 0) {
          min(i)(j) = as(i)(j)
        } else {
          val l = if (j > 0) min(i)(j - 1) else Long.MaxValue
          val u = if (i > 0) min(i - 1)(j) else Long.MaxValue
          min(i)(j) = Math.min(l, u) + as(i)(j)
        }
      }
    }
//    for (aa <- min) {
//      out.println(aa.mkString(" "))
//      out.flush()
//    }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (j > 0 && min(i)(j - 1) <= k) {
          j -= 1
        } else {
          i -= 1
        }
//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
      if (k != as(0)(0)) {
        while (true) {

        }
      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$y $x")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
      case (i, j) => 1L << i //(1024L << i) - j
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(Set.empty[Long])
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val a = as(i)(j)
        val lu = if (i == 0 && j == 0) {
          Set(0L)
        } else {
          val l = if (j > 0) max(i)(j - 1) else Set.empty[Long]
          val u = if (i > 0) max(i - 1)(j) else Set.empty[Long]
          l | u
        }
        max(i)(j) = lu.map(_ + a)
      }
    }

//    println()
//        for (aa <- max) {
//          println(aa.mkString(" "))
//        }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j)(k)) {
          i -= 1
        } else {
          j -= 1
        }
//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
//      if (k != as(0)(0)) {
//        while (true) {
//
//        }
//      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n)(i => Array.fill(n)(100L << i))

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = Math.max(l, u) + as(i)(j)
      }
    }

//    println()
//        for (aa <- max) {
//          println(aa.mkString(" "))
//        }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j) >= k) {
          i -= 1
        } else {
          j -= 1
        }
      }
      if (k != as(0)(0)) {
        while (true) {

        }
      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
      case (i, j) => (1L << (n + n - i - 1)) + (1L << (n - j - 1))
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(Set.empty[Long])
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val a = as(i)(j)
        val lu = if (i == 0 && j == 0) {
          Set(0L)
        } else {
          val l = if (j > 0) max(i)(j - 1) else Set.empty[Long]
          val u = if (i > 0) max(i - 1)(j) else Set.empty[Long]
          l | u
        }
        max(i)(j) = lu.map(_ + a)
      }
    }

//    println()
//        for (aa <- max) {
//          println(aa.mkString(" "))
//        }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j)(k)) {
          i -= 1
        } else {
          j -= 1
        }
//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
//      if (k != as(0)(0)) {
//        while (true) {
//
//        }
//      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
      case (i, j) => 1L << (n + i - j - 1)
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = Math.max(l, u) + as(i)(j)
      }
    }

//    println()
//        for (aa <- max) {
//          println(aa.mkString(" "))
//        }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j) >= k) {
          i -= 1
        } else {
          j -= 1
        }//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
//      if (k != as(0)(0)) {
//        while (true) {
//
//        }
//      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n)(i => Array.fill(n)(1L << i))

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = Math.max(l, u) + as(i)(j)
      }
    }
    for (aa <- max) {
      out.println(aa.mkString(" "))
      out.flush()
    }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j) >= k) {
          i -= 1
        } else {
          j -= 1
        }
      }
      if (k != as(0)(0)) {
        throw new NoSuchElementException
      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
      case (i, j) => if (i % 2 == 0) 0L else 1L << (i + j)
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = Math.max(l, u) + as(i)(j)
      }
    }

//    println()
//        for (aa <- max) {
//          println(aa.mkString(" "))
//        }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j) >= k) {
          i -= 1
        } else {
          j -= 1
        }//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
//      if (k != as(0)(0)) {
//        while (true) {
//
//        }
//      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
//      case (i, j) => (1L << (n + n - i - 1)) + (1L << (n - j - 1))
      case (i, j) => 1L << (n + j - i - 1)
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(Set.empty[Long])
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val a = as(i)(j)
        val lu = if (i == 0 && j == 0) {
          Set(0L)
        } else {
          val l = if (j > 0) max(i)(j - 1) else Set.empty[Long]
          val u = if (i > 0) max(i - 1)(j) else Set.empty[Long]
          l | u
        }
        max(i)(j) = lu.map(_ + a)
      }
    }

//    println()
//        for (aa <- max) {
//          println(aa.mkString(" "))
//        }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j)(k)) {
          i -= 1
        } else {
          j -= 1
        }
//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
//      if (k != as(0)(0)) {
//        while (true) {
//
//        }
//      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
//      case (i, j) => (1L << (n + n - i - 1)) + (1L << (n - j - 1))
      case (i, j) => 1L << (n + i - j)
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(Set.empty[Long])
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val a = as(i)(j)
        val lu = if (i == 0 && j == 0) {
          Set(0L)
        } else {
          val l = if (j > 0) max(i)(j - 1) else Set.empty[Long]
          val u = if (i > 0) max(i - 1)(j) else Set.empty[Long]
          l | u
        }
        max(i)(j) = lu.map(_ + a)
      }
    }

//    println()
//        for (aa <- max) {
//          println(aa.mkString(" "))
//        }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j)(k)) {
          i -= 1
        } else {
          j -= 1
        }
//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
//      if (k != as(0)(0)) {
//        while (true) {
//
//        }
//      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
      case (i, j) => 1L << (n + j - i - 1)
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(Set.empty[Long])
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val a = as(i)(j)
        val lu = if (i == 0 && j == 0) {
          Set(0L)
        } else {
          val l = if (j > 0) max(i)(j - 1) else Set.empty[Long]
          val u = if (i > 0) max(i - 1)(j) else Set.empty[Long]
          l | u
        }
        max(i)(j) = lu.map(_ + a)
      }
    }

//    println()
//        for (aa <- max) {
//          println(aa.mkString(" "))
//        }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && max(i - 1)(j)(k)) {
          i -= 1
        } else {
          j -= 1
        }
//        if (i > 0 && max(i - 1)(j) >= k) {
//          i -= 1
//        } else {
//          j -= 1
//        }
      }
//      if (k != as(0)(0)) {
//        while (true) {
//
//        }
//      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}

import scala.collection.mutable.ArrayBuffer

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

    val n = nextInt
    val as = Array.tabulate(n, n) {
      case (i, j) => if (i % 2 == 0) 0L else 1L << (i + j)
    }

    for (aa <- as) {
      out.println(aa.mkString(" "))
    }
    out.flush()

    val max = Array.fill(n, n)(0L)
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        val l = if (j > 0) max(i)(j - 1) else 0
        val u = if (i > 0) max(i - 1)(j) else 0
        max(i)(j) = l | u | as(i)(j)
      }
    }

    val q = nextInt

    for (_ <- 1 to q) {
      var k = nextLong
      var i, j = n - 1
      val res = ArrayBuffer.empty[(Int, Int)]
      while (i > 0 || j > 0) {
        res += ((i + 1, j + 1))
        k -= as(i)(j)
        if (i > 0 && (max(i - 1)(j) & k) != 0) {
          i -= 1
        } else {
          j -= 1
        }
      }
      res += ((1, 1))
      for ((x, y) <- res.reverseIterator) {
        out.println(s"$x $y")
        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
  }
}


Chouti is working on a strange math problem.There was a sequence of $$$n$$$ positive integers $$$x_1, x_2, \ldots, x_n$$$, where $$$n$$$ is even. The sequence was very special, namely for every integer $$$t$$$ from $$$1$$$ to $$$n$$$, $$$x_1+x_2+...+x_t$$$ is a square of some integer number (that is, a perfect square).Somehow, the numbers with odd indexes turned to be missing, so he is only aware of numbers on even positions, i.e. $$$x_2, x_4, x_6, \ldots, x_n$$$. The task for him is to restore the original sequence. Again, it's your turn to help him.The problem setter might make mistakes, so there can be no possible sequence at all. If there are several possible sequences, you can output any.

The first line contains an even number $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line contains $$$\frac{n}{2}$$$ positive integers $$$x_2, x_4, \ldots, x_n$$$ ($$$1 \le x_i \le 2 \cdot 10^5$$$).

If there are no possible sequence, print "No". Otherwise, print "Yes" and then $$$n$$$ positive integers $$$x_1, x_2, \ldots, x_n$$$ ($$$1 \le x_i \le 10^{13}$$$), where $$$x_2, x_4, \ldots, x_n$$$ should be same as in input data. If there are multiple answers, print any. Note, that the limit for $$$x_i$$$ is larger than for input data. It can be proved that in case there is an answer, there must be a possible sequence satisfying $$$1 \le x_i \le 10^{13}$$$.

NoteIn the first example   $$$x_1=4$$$  $$$x_1+x_2=9$$$  $$$x_1+x_2+x_3=25$$$  $$$x_1+x_2+x_3+x_4=36$$$  $$$x_1+x_2+x_3+x_4+x_5=100$$$  $$$x_1+x_2+x_3+x_4+x_5+x_6=144$$$  All these numbers are perfect squares.In the second example, $$$x_1=100$$$, $$$x_1+x_2=10000$$$. They are all perfect squares. There're other answers possible. For example, $$$x_1=22500$$$ is another answer.In the third example, it is possible to show, that no such sequence exists.

import java.util
import java.util.stream.Collectors

object E {

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

  val n = nextInt
  val xs = readLongs(n / 2)
  val res = new Array[Long](n)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).asInstanceOf[Long]
    r * r == x
  }

  val LIM = 10000000000000L
  var acc = 0L

  var x = 1L
  var bad = false
  var i = 0
  while (i < xs.length) {
    val c = xs(i)
    while (x * x <= acc) {
      x += 1
    }
    var xx = x * x
    while (!bad && !isSquare(xx + c)) {
      x += 1
      xx = x * x
      if (xx - acc > LIM) bad = true
    }
    res(2 * i) = xx - acc
    res(2 * i + 1) = xs(i)
    acc = xx + c
    i += 1
  }

  if (!bad) {
    out.println("Yes")
    out.println(util.Arrays.stream(res)
      .mapToObj(_.toString)
      .collect(
        Collectors
          .joining(" ")))
  } else out.println("No")

  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 readInts(n: Int) = { val a = new Array[Int](n); java.util.Arrays.setAll(a, _ => nextInt); a }
    def readLongs(n: Int) = { val a = new Array[Long](n); java.util.Arrays.setAll(a, _ => nextLong); a }
    def readBigs(n: Int) = Array.fill(n) {nextBig }
  }
}

object E {

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

  val n = nextInt
  val xs = readLongs(n / 2)
  val res = new Array[Long](n)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).asInstanceOf[Long]
    r * r == x
  }

  val LIM = 10000000000000L
  var acc = 0L

  var x = 1L
  var bad = false
  var i = 0
  while (i < xs.length) {
    val c = xs(i)
    while (x * x <= acc) {
      x += 1
    }
    var xx = x * x
    while (!bad && !isSquare(xx + c)) {
      x += 1
      xx = x * x
      if (xx - acc > LIM) bad = true
    }
    res(2 * i) = xx - acc
    res(2 * i + 1) = xs(i)
    acc = xx + c
    i += 1
  }

  if (!bad) {
    out.println("Yes")
    out.println(res.mkString(" "))
  } else out.println("No")

  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 readInts(n: Int) = { val a = new Array[Int](n); java.util.Arrays.setAll(a, _ => nextInt); a }
    def readLongs(n: Int) = { val a = new Array[Long](n); java.util.Arrays.setAll(a, _ => nextLong); a }
    def readBigs(n: Int) = Array.fill(n) {nextBig }
  }
}

object E {

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

  val n = nextInt
  val xs = readLongs(n / 2)
  val res = Array.ofDim[Long](n)

  for (i <- xs.indices) res(2 * i + 1) = xs(i)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).toLong
    r * r == x
  }

  val LIM = 10000000000000L
  var acc = 0L

  var x = 1L
  var bad = false
  for (i <- xs.indices) {
    val c = xs(i)
    while (x * x <= acc) {
      x += 1
    }
    var xx = x * x
    while (!bad && !isSquare(xx + c)) {
      x += 1
      xx = x * x
      if (xx - acc > LIM) bad = true
    }
    res(2 * i) = xx - acc
    acc = xx + c
  }

  if (!bad) {
    out.println("Yes")
    out.println(res.mkString(" "))
  } else out.println("No")

  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 readInts(n: Int) = Array.fill(n) { nextInt }
    def readLongs(n: Int) = Array.fill(n) { nextLong }
    def readBigs(n: Int) = Array.fill(n) {nextBig }
  }
}

object E {

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

  val n = nextInt
  val xs = readLongs(n / 2)
  val res = new Array[Long](n)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).asInstanceOf[Long]
    r * r == x
  }

  val LIM = 10000000000000L
  var acc = 0L

  var x = 1L
  var bad = false
  var i = 0
  while (i < xs.length) {
    val c = xs(i)
    while (x * x <= acc) {
      x += 1
    }
    var xx = x * x
    while (!bad && !isSquare(xx + c)) {
      x += 1
      xx = x * x
      if (xx - acc > LIM) bad = true
    }
    res(2 * i) = xx - acc
    res(2 * i + 1) = xs(i)
    acc = xx + c
    i += 1
  }

  if (!bad) {
    out.println("Yes")
    out.println(res.mkString(" "))
  } else out.println("No")

  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 readInts(n: Int) = Array.fill(n) { val a = new Array[Int](n); java.util.Arrays.setAll(a, _ => nextInt); a }
    def readLongs(n: Int) = Array.fill(n) { nextLong }
    def readBigs(n: Int) = Array.fill(n) {nextBig }
  }
}

object E {

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

  val n = nextInt
  val xs = readLongs(n / 2)
  val res = Array.ofDim[Long](n)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).toLong
    r * r == x
  }

  val LIM = 10000000000000L
  var acc = 0L

  var x = 1L
  var bad = false
  var i = 0
  while (i < xs.length) {
    val c = xs(i)
    while (x * x <= acc) {
      x += 1
    }
    var xx = x * x
    while (!bad && !isSquare(xx + c)) {
      x += 1
      xx = x * x
      if (xx - acc > LIM) bad = true
    }
    res(2 * i) = xx - acc
    res(2 * i + 1) = xs(i)
    acc = xx + c
    i += 1
  }

  if (!bad) {
    out.println("Yes")
    out.println(res.mkString(" "))
  } else out.println("No")

  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 readInts(n: Int) = Array.fill(n) { nextInt }
    def readLongs(n: Int) = Array.fill(n) { nextLong }
    def readBigs(n: Int) = Array.fill(n) {nextBig }
  }
}

object E extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.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 = readLongs(n / 2)

  val res = Array.ofDim[Long](n)

  for (i <- xs.indices) res(2 * i + 1) = xs(i)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).toLong
    r * r == x
  }

  val LIM = 10000000000000L
  var acc = 0L

  var x = 1L
  var bad = false
  for (i <- xs.indices) {
    val c = xs(i)
    while (x * x <= acc) {
      x += 1
    }
    var xx = x * x
    while (!bad && !isSquare(xx + c)) {
      x += 1
      xx = x * x
      if (xx - acc > LIM) bad = true
    }
    res(2 * i) = xx - acc
    acc = xx + c
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  if (!bad) {
    println("Yes")
    println(res.mkString(" "))
  } else println("No")

  Console.flush
}

object E {

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

  val n = nextInt
  val xs = readLongs(n / 2)
  val res = Array.ofDim[Long](n)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).toLong
    r * r == x
  }

  val LIM = 10000000000000L
  var acc = 0L

  var x = 1L
  var bad = false
  var i = 0
  while (i < xs.length) {
    val c = xs(i)
    while (x * x <= acc) {
      x += 1
    }
    var xx = x * x
    while (!bad && !isSquare(xx + c)) {
      x += 1
      xx = x * x
      if (xx - acc > LIM) bad = true
    }
    res(2 * i) = xx - acc
    res(2 * i + 1) = xs(i)
    acc = xx + c
    i += 1
  }

  if (!bad) {
    out.println("Yes")
    out.println(res.mkString(" "))
  } else out.println("No")

  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 readInts(n: Int) = Array.fill(n) { val a = new Array[Int](n); java.util.Arrays.setAll(a, _ => nextInt); a }
    def readLongs(n: Int) = Array.fill(n) { nextLong }
    def readBigs(n: Int) = Array.fill(n) {nextBig }
  }
}

object E {

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

  val n = nextInt
  val xs = readLongs(n / 2)
  val res = new Array[Long](n)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).toLong
    r * r == x
  }

  val LIM = 10000000000000L
  var acc = 0L

  var x = 1L
  var bad = false
  var i = 0
  while (i < xs.length) {
    val c = xs(i)
    while (x * x <= acc) {
      x += 1
    }
    var xx = x * x
    while (!bad && !isSquare(xx + c)) {
      x += 1
      xx = x * x
      if (xx - acc > LIM) bad = true
    }
    res(2 * i) = xx - acc
    res(2 * i + 1) = xs(i)
    acc = xx + c
    i += 1
  }

  if (!bad) {
    out.println("Yes")
    out.println(res.mkString(" "))
  } else out.println("No")

  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 readInts(n: Int) = Array.fill(n) { val a = new Array[Int](n); java.util.Arrays.setAll(a, _ => nextInt); a }
    def readLongs(n: Int) = Array.fill(n) { nextLong }
    def readBigs(n: Int) = Array.fill(n) {nextBig }
  }
}

import java.util
import java.util.stream.Collectors

object E {

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

  val n = nextInt
  val xs = readLongs(n / 2)
  val res = new Array[Long](n)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).toLong
    r * r == x
  }

  val LIM = 10000000000000L
  var acc = 0L

  var x = 1L
  var bad = false
  var i = 0
  while (i < xs.length) {
    val c = xs(i)
    while (x * x <= acc) {
      x += 1
    }
    var xx = x * x
    while (!bad && !isSquare(xx + c)) {
      x += 1
      xx = x * x
      if (xx - acc > LIM) bad = true
    }
    res(2 * i) = xx - acc
    res(2 * i + 1) = xs(i)
    acc = xx + c
    i += 1
  }

  if (!bad) {
    out.println("Yes")
    out.println(util.Arrays.stream(res)
      .mapToObj(_.toString)
      .collect(
        Collectors
          .joining(" ")))
  } else out.println("No")

  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 readInts(n: Int) = { val a = new Array[Int](n); java.util.Arrays.setAll(a, _ => nextInt); a }
    def readLongs(n: Int) = { val a = new Array[Long](n); java.util.Arrays.setAll(a, _ => nextLong); a }
    def readBigs(n: Int) = Array.fill(n) {nextBig }
  }
}

object Main {

  def main(args: Array[String]): Unit = {}

  import IO._

  val n = nextInt
  val (a, b) = n % 4 match {
    case 0 => (1, 'A')
    case 1 => (0, 'A')
    case 2 => (1, 'B')
    case 3 => (2, 'A')
  }
  out.println(s"$a $b")
  out.flush()

  object IO {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    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 readInts(n: Int) = Array.fill(n)(Integer.parseInt(nextToken))
  }

}

object E extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.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 = readLongs(n / 2)

  val res = Array.ofDim[Long](n)

  for (i <- xs.indices) res(2 * i + 1) = xs(i)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).toLong
    r * r == x
  }

  val LIM = 3162277L
  var acc = 0L

  var x = 1
  for (i <- xs.indices) {
    val c = xs(i)
    while (x * x <= acc) {
      x += 1
    }
    var xx = x * x
    while (x <= LIM && !isSquare(xx + c)) {
      x += 1
      xx = x * x
    }
    res(2 * i) = xx - acc
    acc = xx + c
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  if (x <= LIM) {
    println("Yes")
    println(res.mkString(" "))
  } else println("No")

  Console.flush
}

object E extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.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 = readLongs(n / 2)

  val res = Array.ofDim[Long](n)

  for (i <- xs.indices) res(2 * i + 1) = xs(i)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).toLong
    r * r == x
  }

  val LIM = 3162277L
  var acc = 0L

  var x = 1
  for (i <- xs.indices) {
    val c = xs(i)
    var xx = x * x
    while (x <= LIM && (!isSquare(acc + xx) || !isSquare(acc + xx + c))) {
      x += 1
      xx = x * x
    }
    acc += xx
    acc += c
    res(2 * i) = xx
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  if (x <= LIM) {
    println("Yes")
    println(res.mkString(" "))
  } else println("No")

  Console.flush
}

object E extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.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 = readLongs(n / 2)

  val res = Array.ofDim[Long](n)

  for (i <- xs.indices) res(2 * i + 1) = xs(i)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).toLong
    r * r == x
  }

  val LIM = 3162280L

  var x = 1L
  val b = xs.head
  while (!isSquare(b + x * x) && x < LIM) {
    x += 1
  }
  res(0) = x * x
  var acc = x * x + b

  for (i <- 1 until xs.length) {
    val c = xs(i)
    var xx = x * x
    while (x < LIM && (!isSquare(acc + xx) || !isSquare(acc + xx + c))) {
      x += 1
      xx = x * x
    }
    acc += xx
    acc += c
    res(2 * i) = xx
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  if (x < LIM) {
    println("Yes")
    println(res.mkString(" "))
  } else println("No")

  Console.flush
}

object E extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.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 = readLongs(n / 2)

  val res = Array.ofDim[Long](n)

  for (i <- xs.indices) res(2 * i + 1) = xs(i)

  def isSquare(x: Long): Boolean = {
    val r = Math.sqrt(x).toLong
    r * r == x
  }

  val LIM = 3162277L
  var acc = 0L

  var x = 1
  for (i <- xs.indices) {
    val c = xs(i)
    var xx = x * x
    while (x < LIM && (!isSquare(acc + xx) || !isSquare(acc + xx + c))) {
      x += 1
      xx = x * x
    }
    acc += xx
    acc += c
    res(2 * i) = xx
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  if (x < LIM) {
    println("Yes")
    println(res.mkString(" "))
  } else println("No")

  Console.flush
}


This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You may also refer to the guide on interactive problems: https://codeforces.com/blog/entry/45307.You are given a string $$$t$$$ consisting of $$$n$$$ lowercase Latin letters. This string was cyphered as follows: initially, the jury had a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. Then they applied a sequence of no more than $$$n$$$ (possibly zero) operations. $$$i$$$-th operation is denoted by two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i, b_i \le n$$$), and means swapping two elements of the string with indices $$$a_i$$$ and $$$b_i$$$. All operations were done in the order they were placed in the sequence. For example, if $$$s$$$ is xyz and $$$2$$$ following operations are performed: $$$a_1 = 1, b_1 = 2$$$; $$$a_2 = 2, b_2 = 3$$$, then after the first operation the current string is yxz, and after the second operation the current string is yzx, so $$$t$$$ is yzx.You are asked to restore the original string $$$s$$$. Unfortunately, you have no information about the operations used in the algorithm (you don't even know if there were any operations in the sequence). But you may run the same sequence of operations on any string you want, provided that it contains only lowercase Latin letters and its length is $$$n$$$, and get the resulting string after those operations.Can you guess the original string $$$s$$$ asking the testing system to run the sequence of swaps no more than $$$3$$$ times?The string $$$s$$$ and the sequence of swaps are fixed in each test; the interactor doesn't try to adapt the test to your solution.

Initially the testing system sends one string $$$t$$$, consisting of lowercase Latin letters ($$$1 \le |t| = n \le 10^4$$$).

To give the answer, your program should print one line $$$!$$$ $$$s$$$ with a line break in the end. After that, it should flush the output and terminate gracefully.

NoteIn the sample, the testcase described in the statement is used. The participant asks the first query with string baa, which is transformed to aab. The second query contains string aba, which is transformed to baa. The third query contains string aab, which is transformed to aba. The participant can deduce that the initial string $$$s$$$ was xyz.Note for hacking phase:To submit a test in hacking phase, you should provide it in the following format:The first line should contain the string $$$s$$$ you guess, consisting of $$$n \in [1, 10000]$$$ lowercase Latin letters.The second line should contain $$$k$$$ ($$$0 \le k \le n$$$) — the number of swap operations in the sequence.Then $$$k$$$ lines should follow, $$$i$$$-th of them should denote $$$i$$$-th operation with two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i, b_i \le n$$$).For example, the sample test would look like that:xyz21 22 3

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()
    val N = S.length

    // 裏に1-Nを並び替えた数列があると考える

    /**
      * 26進表現にした時、k桁目がa-zの場所はどこか
      */
    def queryDigits(k: Int): Array[mutable.Set[Int]] = {
      val div = math.round(math.pow(26, k)).toInt
      val str = map(N) { i =>
        ('a' + i / div % 26).toChar
      }.mkString

//      debug(s"query $str")

      out.println(s"? $str")
      out.flush()

      val res = ns()
      val pos = Array.fill[mutable.Set[Int]](26)(mutable.Set())
      REP(N) { i =>
        pos(res(i) - 'a') += i
      }
      pos
    }

    // 桁 => letter => {pos}
    val d = map(3)(queryDigits)
//    REP(3) { i =>
//      debug(d(i).mkString)
//    }

    val f = Array.ofDim[Int](N) // 変換関数
    REP(26) { i =>
      REP(26) { j =>
        val mg01 = d(0)(i).intersect(d(1)(j))
        REP(26) { k =>
          val mged = mg01.intersect(d(2)(k))
          val pos = i + j * 26 + k * 26 * 26
          if (pos < N && mged.nonEmpty) f(i + j * 26 + k * 26 * 26) = mged.head
        }
      }
    }

//    debug("f")
//    debug(f)

    val g = Array.ofDim[Int](N) // 逆関数
    REP(N) { i =>
      g(f(i)) = i
    }

//    debug("g")
//    debug(g)

    val ans = Array.ofDim[Char](N)
    REP(N) { i =>
      ans(g(i)) = S(i)
    }

//    debug(s"ans ${ans.mkString}")

    out.println(s"! ${ans.mkString}")
    out.flush()
  }

  def debug(as: Array[Boolean]): Unit = {
    System.err.println(as.map(x => if(x) "1" else "0").mkString)
  }

  def debug(as: Array[Int]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(as: Array[Long]): Unit = {
    System.err.println(as.mkString(" "))
  }

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

  def debug(num: Long): Unit = {
    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 = 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
  }
}