import java.util

object D 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) }

  val Array(n) = readInts(1)
  val as, bs = Array.fill(n){ readLine.toCharArray }

  val isDiff = Array.ofDim[Boolean](n)
  var i = 0
  var first = -1
  while (i < n) {
    if (!util.Arrays.equals(as(i), bs(i))) {
      first = i
      isDiff(i) = true
    }
    i += 1
  }

  val aFirst = as(first)
  val bFirst = bs(first)
  var lMax = 0
  while (aFirst(lMax) == bFirst(lMax)) lMax += 1
  var rMin = aFirst.length - 1
  while (aFirst(rMin) == bFirst(rMin)) rMin -= 1
  var lFirst = 0
  var rFirst = aFirst.length - 1
  var s = as(first)
  var t = bs(first)
  val sMin = s.slice(lMax, rMin + 1)
  val tMin = t.slice(lMax, rMin + 1)

  def patch(x: Array[Char], y: Array[Char], pos: Int): Array[Char] = {
    val ss = x.clone()
    var i = 0
    while (i < y.length) {
      ss(pos + i) = y(i)
      i += 1
    }
    ss
  }

  def kmp(t: Array[Char], p: Array[Char]): Int = {
    val m = p.length
    val next = Array.fill(m + 1)(0)
    var k = 0
    var j = 1
    while (j < m) {
      while (k > 0 && p(k) != p(j)) k = next(k)
      if (p(k) == p(j)) k += 1
      next(j + 1) = k
      j += 1
    }

    var pos = -1
    j = 0
    var i = 0
    while (i < t.length && pos < 0) {
      while (j > 0 && p(j) != t(i)) j = next(j)
      if (p(j) == t(i)) j += 1
      if (j == m) {
        pos = i - m + 1
        j = next(j)
      }
      i += 1
    }

    pos
  }

  for (i <- 0 until n) {
    if (isDiff(i)) {
      val a = as(i)
      val b = bs(i)
      val pos = kmp(a, s)
      val mod = if (pos < 0) a
      else patch(a, t, pos)
      if (!util.Arrays.equals(mod, b)) {
        var l = 0
        while (a(l) == b(l)) l += 1
        var r = a.length - 1
        while (a(r) == b(r)) r -= 1
        if (r - l == rMin - lMax /* && util.Arrays.equals(a.slice(l, r + 1), sMin) && util.Arrays.equals(b.slice(l, r + 1), tMin)*/) {
          var ll = lMax
          while (l > 0 && ll > lFirst && a(l - 1) == aFirst(ll - 1) && b(l - 1) == bFirst(ll - 1)) {
            l -= 1
            ll -= 1
          }
          var rr = rMin
          while (r < a.length - 1 && rr < rFirst && a(r + 1) == aFirst(rr + 1) && b(r + 1) == bFirst(rr + 1)) {
            r += 1
            rr += 1
          }
          lFirst = ll
          rFirst = rr
          if (rr - ll + 1 != s.length) {
            s = aFirst.slice(ll, rr + 1)
            t = bFirst.slice(ll, rr + 1)
          }
        }
      }
    }
  }

  var ok = true
  for (i <- 0 until n) {
    if (ok) {
      val pos = kmp(as(i), s)
      val mod = if (pos < 0) as(i)
      else patch(as(i), t, pos)
      if (!util.Arrays.equals(mod, bs(i))) ok = false
    }
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))
  if (ok) {
    println("YES")
    println(s.mkString)
    println(t.mkString)
  } else println("NO")
  Console.flush()
}

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 N = ni()
    val A, B = Array.ofDim[String](N)
    rep(N) { i =>
      A(i) = ns()
    }
    rep(N) { i =>
      B(i) = ns()
    }

    /**
      * [l, r)
      */
    case class Replace(l: Int, r: Int, i: Int)

    def calc(i: Int): Option[Replace] = {
      var l, r = -1
      rep(A(i).length) { j =>
        if (A(i).charAt(j) != B(i).charAt(j)) {
          if (l == -1) l = j
          r = j
        }
      }
      if (r == -1) None
      else Some(Replace(l, r + 1, i))
    }

    def test(s: String, t: String, kmp: KMP): Boolean = {
      0 until N forall { i =>
        val ix = kmp.findFirst(A(i))
        if (ix == -1)
          A(i) == B(i)
        else {
          var ok = true
          rep(A(i).length) { j =>
            if (j < ix || j >= ix + t.length) {
              ok &&= B(i).charAt(j) == A(i).charAt(j)
            } else {
              ok &&= B(i).charAt(j) == t(j - ix)
            }
          }
          ok
        }
      }
    }

    val diffs = map(N)(calc).flatten
    var lastReplace: Option[Replace] = None
    var cntL, cntR = -1 // 左右の同じものが続く回数
    diffs.foreach { replace =>
      val l = replace.l
      val r = replace.r
      val i = replace.i
        // cntL, cntRはできるだけ広くとるほうがSameとバッティングしにくいので真に有利になる
        lastReplace match {
          case None =>
            cntL = l
            cntR = A(i).length - r

          case Some(last: Replace) =>
            var j = 1
            val A0 = A(i)
            val A1 = A(last.i)
            while(l - j >= 0 && j <= cntL && A0.charAt(l - j) == A1.charAt(last.l - j)) {
              j += 1
            }
            cntL = j - 1

            j = 0
            while(r + j < A0.length && j < cntR && A0.charAt(r + j) == A1.charAt(last.r + j)) {
              j += 1
            }
            cntR = j
        }

        lastReplace = Some(replace)
    }

    val Some(last: Replace) = lastReplace
    val s = A(last.i).substring(last.l - cntL, last.r + cntR)
    val t = B(last.i).substring(last.l - cntL, last.r + cntR)

    if (!test(s, t, new KMP(s))) {
      out.println("NO")
    } else {
      out.println("YES")
      out.println(s)
      out.println(t)
    }
  }

  class KMP(word: String) {
    val kmp: Array[Int] = Array.ofDim[Int](word.length + 1)
    2 to word.length foreach { i =>
      var j = kmp(i - 1)
      var continues = true
      while(continues) {
        if (word(j) == word(i - 1)) {
          j += 1
          continues = false
        } else if (j == 0) continues = false
        else j = kmp(j)
      }
      kmp(i) = j
    }

    def findFirst(text: String): Int = {
      var j = 0
      rep(text.length) { i =>
        var continues = true
        while(continues) {
          if (word(j) == text(i)) {
            j += 1
            continues = false
          } else if (j == 0) continues = false
          else j = kmp(j)
        }
        if (j == word.length) return i - word.length + 1
      }
      -1
    }
  }

  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)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

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

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

import java.util

import scala.collection.mutable

// https://codeforces.com/contest/1055/problem/D
object DAhoCorasic 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) }

  val Array(n) = readInts(1)
  val as, bs = Array.fill(n){ readLine.toCharArray }

  val isDiff = Array.ofDim[Boolean](n)
  var i = 0
  var first = -1
  while (i < n) {
    if (!util.Arrays.equals(as(i), bs(i))) {
      first = i
      isDiff(i) = true
    }
    i += 1
  }

  val aFirst = as(first)
  val bFirst = bs(first)
  var lMax = 0
  while (aFirst(lMax) == bFirst(lMax)) lMax += 1
  var rMin = aFirst.length - 1
  while (aFirst(rMin) == bFirst(rMin)) rMin -= 1
  var lFirst = 0
  var rFirst = aFirst.length - 1
  var s = as(first)
  var t = bs(first)
  var ahoCorasic = AhoCorasic(s)
  val sMin = s.slice(lMax, rMin + 1)
  val tMin = t.slice(lMax, rMin + 1)

  def patch(x: Array[Char], y: Array[Char], pos: Int): Array[Char] = {
    val ss = x.clone()
    var i = 0
    while (i < y.length) {
      ss(pos + i) = y(i)
      i += 1
    }
    ss
  }

  for (i <- 0 until n) {
    if (isDiff(i)) {
      val a = as(i)
      val b = bs(i)
      val pos = ahoCorasic.findIn(a) - s.length + 1
      val mod = if (pos < 0) a
      else patch(a, t, pos)
      if (!util.Arrays.equals(mod, b)) {
        var l = 0
        while (a(l) == b(l)) l += 1
        var r = a.length - 1
        while (a(r) == b(r)) r -= 1
        if (r - l == rMin - lMax /* && util.Arrays.equals(a.slice(l, r + 1), sMin) && util.Arrays.equals(b.slice(l, r + 1), tMin)*/) {
          var ll = lMax
          while (l > 0 && ll > lFirst && a(l - 1) == aFirst(ll - 1) && b(l - 1) == bFirst(ll - 1)) {
            l -= 1
            ll -= 1
          }
          var rr = rMin
          while (r < a.length - 1 && rr < rFirst && a(r + 1) == aFirst(rr + 1) && b(r + 1) == bFirst(rr + 1)) {
            r += 1
            rr += 1
          }
          lFirst = ll
          rFirst = rr
          if (rr - ll + 1 != s.length) {
            s = aFirst.slice(ll, rr + 1)
            t = bFirst.slice(ll, rr + 1)
            ahoCorasic = AhoCorasic(s)
          }
        }
      }
    }
  }

  var ok = true
  for (i <- 0 until n) {
    if (ok) {
      val pos = ahoCorasic.findIn(as(i)) - s.length + 1
      val mod = if (pos < 0) as(i)
      else patch(as(i), t, pos)
      if (!util.Arrays.equals(mod, bs(i))) ok = false
    }
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))
  if (ok) {
    println("YES")
    println(s.mkString)
    println(t.mkString)
  } else println("NO")
  Console.flush()

  import AhoCorasic._

  class AhoCorasic private(private val trieRoot: TrieNode) {

    def newMatcher: Matcher = new Matcher

    def findIn(t: Array[Char]): Int = {
      var currentNode = trieRoot
      var i = 0
      do {
        currentNode = currentNode.children(t(i) - 'a')
        i += 1
      } while (currentNode.matchFor < 0 && i < t.length)
      if (currentNode.matchFor == 0) i - 1 else -1
    }

    class Matcher private[AhoCorasic] () {

      private var currentNode = trieRoot

      def apply(rawCh: Byte): Int = {
        val ch = java.lang.Byte.toUnsignedInt(rawCh)
        currentNode = currentNode.children(ch)
        currentNode.matchFor
      }
    }

  }

  object AhoCorasic {

    private final val AlphabetSize = 'z' - 'a' + 1

    private class TrieNode {
      val children: Array[TrieNode] = Array.ofDim(AlphabetSize)
      var matchFor: Int = -1
      def hasChildFor(ch: Int): Boolean = children(ch) != null
    }

    def apply(searchStrings: Array[Char]*): AhoCorasic = {

      val trieRoot = buildTrie(searchStrings)

      linkSuffixes(trieRoot)

      new AhoCorasic(trieRoot)
    }

    private def buildTrie(searchStrings: Seq[Array[Char]]): TrieNode = {

      val trieRoot = new TrieNode

      for (stringId <- searchStrings.indices) {
        val str = searchStrings(stringId)
        var currentNode = trieRoot
        for (ch0 <- str) {
          val ch = ch0 - 'a'
          if (!currentNode.hasChildFor(ch)) {
            currentNode.children(ch) = new TrieNode
          }
          currentNode = currentNode.children(ch)
        }
        currentNode.matchFor = stringId
      }
      trieRoot
    }

    private def linkSuffixes(trieRoot: TrieNode): Unit = {

      val queue = mutable.Queue(trieRoot)
      val suffixLinks = mutable.AnyRefMap.empty[TrieNode, TrieNode]

      while (queue.nonEmpty) {
        val v = queue.dequeue()
        val u = suffixLinks.getOrElse(v, v)
        if (v.matchFor == -1) v.matchFor = u.matchFor
        for (ch <- 0 until AlphabetSize) {
          if (v.hasChildFor(ch)) {
            suffixLinks(v.children(ch)) = if (suffixLinks.contains(v) && u.hasChildFor(ch)) u.children(ch) else trieRoot
            queue += v.children(ch)
          } else {
            v.children(ch) = if (u.hasChildFor(ch)) u.children(ch) else trieRoot
          }
        }
      }
    }

  }

}

import java.util

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

// https://codeforces.com/contest/1055/problem/D
object DAhoCorasic 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) }

  val Array(n) = readInts(1)
  val as, bs = Array.fill(n){ readLine.toCharArray.map(c => (c - 'a').toByte) }

  val isDiff = Array.ofDim[Boolean](n)
  var i = 0
  var first = -1
  while (i < n) {
    if (!util.Arrays.equals(as(i), bs(i))) {
      first = i
      isDiff(i) = true
    }
    i += 1
  }

  val aFirst = as(first)
  val bFirst = bs(first)
  var lMax = 0
  while (aFirst(lMax) == bFirst(lMax)) lMax += 1
  var rMin = aFirst.length - 1
  while (aFirst(rMin) == bFirst(rMin)) rMin -= 1
  var lFirst = 0
  var rFirst = aFirst.length - 1
  var s = as(first)
  var t = bs(first)
  var ahoCorasic = AhoCorasic(s)
  val sMin = s.slice(lMax, rMin + 1)
  val tMin = t.slice(lMax, rMin + 1)

  def patch(x: Array[Byte], y: Array[Byte], pos: Int): Array[Byte] = {
    val ss = x.clone()
    var i = 0
    while (i < y.length) {
      ss(pos + i) = y(i)
      i += 1
    }
    ss
  }

  for (i <- 0 until n) {
    if (isDiff(i)) {
      val a = as(i)
      val b = bs(i)
      val pos = ahoCorasic.findIn(a) - s.length + 1
      val mod = if (pos < 0) a
      else patch(a, t, pos)
      if (!util.Arrays.equals(mod, b)) {
        var l = 0
        while (a(l) == b(l)) l += 1
        var r = a.length - 1
        while (a(r) == b(r)) r -= 1
        if (r - l == rMin - lMax /* && util.Arrays.equals(a.slice(l, r + 1), sMin) && util.Arrays.equals(b.slice(l, r + 1), tMin)*/) {
          var ll = lMax
          while (l > 0 && ll > lFirst && a(l - 1) == aFirst(ll - 1) && b(l - 1) == bFirst(ll - 1)) {
            l -= 1
            ll -= 1
          }
          var rr = rMin
          while (r < a.length - 1 && rr < rFirst && a(r + 1) == aFirst(rr + 1) && b(r + 1) == bFirst(rr + 1)) {
            r += 1
            rr += 1
          }
          lFirst = ll
          rFirst = rr
          if (rr - ll + 1 != s.length) {
            s = aFirst.slice(ll, rr + 1)
            t = bFirst.slice(ll, rr + 1)
            ahoCorasic = AhoCorasic(s)
          }
        }
      }
    }
  }

  var ok = true
  for (i <- 0 until n) {
    if (ok) {
      val pos = ahoCorasic.findIn(as(i)) - s.length + 1
      val mod = if (pos < 0) as(i)
      else patch(as(i), t, pos)
      if (!util.Arrays.equals(mod, bs(i))) ok = false
    }
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))
  if (ok) {
    println("YES")
    println(s.map(c => (c + 'a').toChar).mkString)
    println(t.map(c => (c + 'a').toChar).mkString)
  } else println("NO")
  Console.flush()

  import AhoCorasic._

  class AhoCorasic private(
      private[AhoCorasic] val jumpTable: Array[Int],
      private[AhoCorasic] val matchFor: Array[Int]) {

    def findIn(t: Array[Byte]): Int = {
      var currentPosition = 0
      var i = 0
      do {
        currentPosition = jumpTable(currentPosition * AlphabetSize + t(i))
        i += 1
      } while (matchFor(currentPosition) < 0 && i < t.length)
      if (matchFor(currentPosition) == 0) i - 1 else -1
    }

    def newMatcher: Matcher = new Matcher

    class Matcher private[AhoCorasic]() {

      private var currentPosition = 0

      def apply(ch: Byte): Int = {
        currentPosition = jumpTable(currentPosition * AlphabetSize + ch)
        matchFor(currentPosition)
      }
    }

  }

  object AhoCorasic {

    private final val AlphabetSize = 26

    def apply(searchStrings: Array[Byte]*): AhoCorasic = {

      val (jumpTable, matchFor) = buildJumpTable(searchStrings)

      linkSuffixes(jumpTable, matchFor)

      new AhoCorasic(jumpTable, matchFor)
    }

    private def buildJumpTable(searchStrings: Seq[Array[Byte]]): (Array[Int], Array[Int]) = {

      val emptyJumpTableSegment = Array.fill(AlphabetSize)(-1)
      val jumpTableBuilder = ArrayBuffer(emptyJumpTableSegment: _*)
      val matchForBuilder = ArrayBuffer(-1)

      for (stringId <- searchStrings.indices) {
        val str = searchStrings(stringId)
        var currentPosition = 0
        for (ch <- str) {
          val next = currentPosition * AlphabetSize + ch
          if (jumpTableBuilder(next) == -1) {
            jumpTableBuilder(next) = matchForBuilder.size
            jumpTableBuilder ++= emptyJumpTableSegment
            matchForBuilder += -1
          }
          currentPosition = jumpTableBuilder(next)
        }
        matchForBuilder(currentPosition) = stringId
      }

      (jumpTableBuilder.toArray, matchForBuilder.toArray)
    }

    private def linkSuffixes(jumpTable: Array[Int], matchFor: Array[Int]): Unit = {

      val queue = mutable.Queue(0)
      val suffixLinks = Array.fill(matchFor.length)(-1)

      while (queue.nonEmpty) {
        val v = queue.dequeue()
        val u = if (v == 0) 0 else suffixLinks(v)
        if (matchFor(v) == -1) matchFor(v) = matchFor(u)
        for (ch <- 0 until AlphabetSize) {
          val vIndex = v * AlphabetSize + ch
          val uIndex = u * AlphabetSize + ch
          if (jumpTable(vIndex) != -1) {
            suffixLinks(jumpTable(vIndex)) = if (v > 0 && jumpTable(uIndex) != -1) jumpTable(uIndex) else 0
            queue += jumpTable(vIndex)
          } else {
            jumpTable(vIndex) = if (jumpTable(uIndex) != -1) jumpTable(uIndex) else 0
          }
        }
      }
    }

  }

}

import java.util

import scala.collection.mutable

// https://codeforces.com/contest/1055/problem/D
object DAhoCorasic 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) }

  val Array(n) = readInts(1)
  val as, bs = Array.fill(n){ readLine.toCharArray.map(c => (c - 'a').toByte) }

  val isDiff = Array.ofDim[Boolean](n)
  var i = 0
  var first = -1
  while (i < n) {
    if (!util.Arrays.equals(as(i), bs(i))) {
      first = i
      isDiff(i) = true
    }
    i += 1
  }

  val aFirst = as(first)
  val bFirst = bs(first)
  var lMax = 0
  while (aFirst(lMax) == bFirst(lMax)) lMax += 1
  var rMin = aFirst.length - 1
  while (aFirst(rMin) == bFirst(rMin)) rMin -= 1
  var lFirst = 0
  var rFirst = aFirst.length - 1
  var s = as(first)
  var t = bs(first)
  var ahoCorasic = AhoCorasic(s)
  val sMin = s.slice(lMax, rMin + 1)
  val tMin = t.slice(lMax, rMin + 1)

  def patch(x: Array[Byte], y: Array[Byte], pos: Int): Array[Byte] = {
    val ss = x.clone()
    var i = 0
    while (i < y.length) {
      ss(pos + i) = y(i)
      i += 1
    }
    ss
  }

  for (i <- 0 until n) {
    if (isDiff(i)) {
      val a = as(i)
      val b = bs(i)
      val pos = ahoCorasic.findIn(a) - s.length + 1
      val mod = if (pos < 0) a
      else patch(a, t, pos)
      if (!util.Arrays.equals(mod, b)) {
        var l = 0
        while (a(l) == b(l)) l += 1
        var r = a.length - 1
        while (a(r) == b(r)) r -= 1
        if (r - l == rMin - lMax /* && util.Arrays.equals(a.slice(l, r + 1), sMin) && util.Arrays.equals(b.slice(l, r + 1), tMin)*/) {
          var ll = lMax
          while (l > 0 && ll > lFirst && a(l - 1) == aFirst(ll - 1) && b(l - 1) == bFirst(ll - 1)) {
            l -= 1
            ll -= 1
          }
          var rr = rMin
          while (r < a.length - 1 && rr < rFirst && a(r + 1) == aFirst(rr + 1) && b(r + 1) == bFirst(rr + 1)) {
            r += 1
            rr += 1
          }
          lFirst = ll
          rFirst = rr
          if (rr - ll + 1 != s.length) {
            s = aFirst.slice(ll, rr + 1)
            t = bFirst.slice(ll, rr + 1)
            ahoCorasic = AhoCorasic(s)
          }
        }
      }
    }
  }

  var ok = true
  for (i <- 0 until n) {
    if (ok) {
      val pos = ahoCorasic.findIn(as(i)) - s.length + 1
      val mod = if (pos < 0) as(i)
      else patch(as(i), t, pos)
      if (!util.Arrays.equals(mod, bs(i))) ok = false
    }
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))
  if (ok) {
    println("YES")
    println(s.map(c => (c + 'a').toChar).mkString)
    println(t.map(c => (c + 'a').toChar).mkString)
  } else println("NO")
  Console.flush()

  import AhoCorasic._

  class AhoCorasic private(private val trieRoot: TrieNode) {

    def newMatcher: Matcher = new Matcher

    def findIn(t: Array[Byte]): Int = {
      var currentNode = trieRoot
      var i = 0
      do {
        currentNode = currentNode.children(t(i))
        i += 1
      } while (currentNode.matchFor < 0 && i < t.length)
      if (currentNode.matchFor == 0) i - 1 else -1
    }

    class Matcher private[AhoCorasic] () {

      private var currentNode = trieRoot

      def apply(rawCh: Byte): Int = {
        val ch = java.lang.Byte.toUnsignedInt(rawCh)
        currentNode = currentNode.children(ch)
        currentNode.matchFor
      }
    }

  }

  object AhoCorasic {

    private final val AlphabetSize = 'z' - 'a' + 1

    private class TrieNode {
      val children: Array[TrieNode] = Array.ofDim(AlphabetSize)
      var matchFor: Int = -1
      def hasChildFor(ch: Int): Boolean = children(ch) != null
    }

    def apply(searchStrings: Array[Byte]*): AhoCorasic = {

      val trieRoot = buildTrie(searchStrings)

      linkSuffixes(trieRoot)

      new AhoCorasic(trieRoot)
    }

    private def buildTrie(searchStrings: Seq[Array[Byte]]): TrieNode = {

      val trieRoot = new TrieNode

      for (stringId <- searchStrings.indices) {
        val str = searchStrings(stringId)
        var currentNode = trieRoot
        for (ch0 <- str) {
          val ch = ch0
          if (!currentNode.hasChildFor(ch)) {
            currentNode.children(ch) = new TrieNode
          }
          currentNode = currentNode.children(ch)
        }
        currentNode.matchFor = stringId
      }
      trieRoot
    }

    private def linkSuffixes(trieRoot: TrieNode): Unit = {

      val queue = mutable.Queue(trieRoot)
      val suffixLinks = mutable.AnyRefMap.empty[TrieNode, TrieNode]

      while (queue.nonEmpty) {
        val v = queue.dequeue()
        val u = suffixLinks.getOrElse(v, v)
        if (v.matchFor == -1) v.matchFor = u.matchFor
        for (ch <- 0 until AlphabetSize) {
          if (v.hasChildFor(ch)) {
            suffixLinks(v.children(ch)) = if (suffixLinks.contains(v) && u.hasChildFor(ch)) u.children(ch) else trieRoot
            queue += v.children(ch)
          } else {
            v.children(ch) = if (u.hasChildFor(ch)) u.children(ch) else trieRoot
          }
        }
      }
    }

  }

}

import java.util

// https://codeforces.com/contest/1055/problem/D
object DKmp 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) }

  val Array(n) = readInts(1)
  val as, bs = Array.fill(n){ readLine.toCharArray }

  val isDiff = Array.ofDim[Boolean](n)
  var i = 0
  var first = -1
  while (i < n) {
    if (!util.Arrays.equals(as(i), bs(i))) {
      first = i
      isDiff(i) = true
    }
    i += 1
  }

  val aFirst = as(first)
  val bFirst = bs(first)
  var lMax = 0
  while (aFirst(lMax) == bFirst(lMax)) lMax += 1
  var rMin = aFirst.length - 1
  while (aFirst(rMin) == bFirst(rMin)) rMin -= 1
  var lFirst = 0
  var rFirst = aFirst.length - 1
  var s = as(first)
  var t = bs(first)
  var kmpNext = kmpPattern(s)
  val sMin = s.slice(lMax, rMin + 1)
  val tMin = t.slice(lMax, rMin + 1)

  def patch(x: Array[Char], y: Array[Char], pos: Int): Array[Char] = {
    val ss = x.clone()
    var i = 0
    while (i < y.length) {
      ss(pos + i) = y(i)
      i += 1
    }
    ss
  }

  def kmpPattern(p: Array[Char]): Array[Int] = {
    val m = p.length
    val next = Array.fill(m + 1)(0)
    var k = 0
    var j = 1
    while (j < m) {
      while (k > 0 && p(k) != p(j)) k = next(k)
      if (p(k) == p(j)) k += 1
      next(j + 1) = k
      j += 1
    }
    next
  }

  def kmp(t: Array[Char], p: Array[Char], next: Array[Int]): Int = {
    val m = p.length

    var pos = -1
    var j = 0
    var i = 0
    while (i < t.length && pos < 0) {
      while (j > 0 && p(j) != t(i)) j = next(j)
      if (p(j) == t(i)) j += 1
      if (j == m) {
        pos = i - m + 1
        j = next(j)
      }
      i += 1
    }

    pos
  }

  for (i <- 0 until n) {
    if (isDiff(i)) {
      val a = as(i)
      val b = bs(i)
      val pos = kmp(a, s, kmpNext)
      val mod = if (pos < 0) a
      else patch(a, t, pos)
      if (!util.Arrays.equals(mod, b)) {
        var l = 0
        while (a(l) == b(l)) l += 1
        var r = a.length - 1
        while (a(r) == b(r)) r -= 1
        if (r - l == rMin - lMax /* && util.Arrays.equals(a.slice(l, r + 1), sMin) && util.Arrays.equals(b.slice(l, r + 1), tMin)*/) {
          var ll = lMax
          while (l > 0 && ll > lFirst && a(l - 1) == aFirst(ll - 1) && b(l - 1) == bFirst(ll - 1)) {
            l -= 1
            ll -= 1
          }
          var rr = rMin
          while (r < a.length - 1 && rr < rFirst && a(r + 1) == aFirst(rr + 1) && b(r + 1) == bFirst(rr + 1)) {
            r += 1
            rr += 1
          }
          lFirst = ll
          rFirst = rr
          if (rr - ll + 1 != s.length) {
            s = aFirst.slice(ll, rr + 1)
            t = bFirst.slice(ll, rr + 1)
            kmpNext = kmpPattern(s)
          }
        }
      }
    }
  }

  var ok = true
  for (i <- 0 until n) {
    if (ok) {
      val pos = kmp(as(i), s, kmpNext)
      val mod = if (pos < 0) as(i)
      else patch(as(i), t, pos)
      if (!util.Arrays.equals(mod, bs(i))) ok = false
    }
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))
  if (ok) {
    println("YES")
    println(s.mkString)
    println(t.mkString)
  } else println("NO")
  Console.flush()
}

object Main {
  import java.io.PrintStream

  def main(args: Array[String]): Unit = {
    val s = new Main()
    val ps = new PrintStream(Console.out)
    Console.withOut(ps) {
      s.solve()
    }
    ps.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
  import scala.Console

  val MOD = 1000000007

  def solve(): Unit = {
    val N = ni()
    val A, B = Array.ofDim[String](N)
    rep(N) { i =>
      A(i) = ns()
    }
    rep(N) { i =>
      B(i) = ns()
    }

    sealed trait Diff
    case class Never() extends Diff
    case class Same() extends Diff
    case class One(l: Int, r: Int) extends Diff

    def calc(i: Int): Diff = {
      var state = 0
      var ok = true
      var l, r = -1
      rep(N) { j =>
        state match {
          case 0 =>
            if (A(i)(j) != B(i)(j)) {
              l = j
              state = 1
            }
          case 1 =>
            if (A(i)(j) == B(i)(j)) {
              r = j
              state = 2
            }

          case 2 =>
            if (A(i)(j) != B(i)(j)) ok = false
        }
      }

      if (!ok) Never()
      else if (state == 0) Same()
      else if (state == 1) One(l, A(i).length)
      else One(l, r)
    }

    val diffs = map(N)(calc)
    var s: String = ""
    var t: String = ""
    var ok = true
    rep(N) { i =>
      diffs(i) match {
        case Never() => ok = false
        case Same() =>
        case One(l, r) =>
          val s1 = A(i).substring(l, r)
          val t1 = B(i).substring(l, r)
          if (s.isEmpty) s = s1
          if (t.isEmpty) t = t1

          ok &&= s == s1 && t == t1
      }
    }

    if (!ok) {
      println("NO")
    } else {
      println("YES")
      println(s)
      println(t)
    }

  }

  class InputReader(reader: BufferedReader) {
    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(Console.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)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

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

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

object 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 N = ni()
    val A, B = Array.ofDim[String](N)
    rep(N) { i =>
      A(i) = ns()
    }
    rep(N) { i =>
      B(i) = ns()
    }

    sealed trait Diff
    case class Never() extends Diff
    case class Same() extends Diff
    case class One(l: Int, r: Int) extends Diff

    def calc(i: Int): Diff = {
      var state = 0
      var ok = true
      var l, r = -1
      rep(N) { j =>
        state match {
          case 0 =>
            if (A(i)(j) != B(i)(j)) {
              l = j
              state = 1
            }
          case 1 =>
            if (A(i)(j) == B(i)(j)) {
              r = j
              state = 2
            }

          case 2 =>
            if (A(i)(j) != B(i)(j)) ok = false
        }
      }

      if (!ok) Never()
      else if (state == 0) Same()
      else if (state == 1) One(l, A(i).length)
      else One(l, r)
    }

    val diffs = map(N)(calc)
    var s: String = ""
    var t: String = ""
    var ok = true
    rep(N) { i =>
      diffs(i) match {
        case Never() => ok = false
        case Same() =>
        case One(l, r) =>
          val s1 = A(i).substring(l, r)
          val t1 = B(i).substring(l, r)
          if (s.isEmpty) s = s1
          if (t.isEmpty) t = t1

          ok &&= s == s1 && t == t1
      }
    }

    rep(N) { i =>
      if (diffs(i) == Same()) {
        val ix = A(i).indexOf(s)
        ok &&= ix == -1 || {
          B(i).substring(ix, s.length) == t
        }
      }
    }

    if (!ok) {
      out.println("NO")
    } else {
      out.println("YES")
      out.println(s)
      out.println(t)
    }

  }

  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)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

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

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

object 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 N = ni()
    val A, B = Array.ofDim[String](N)
    rep(N) { i =>
      A(i) = ns()
    }
    rep(N) { i =>
      B(i) = ns()
    }

    sealed trait Diff
    case class Same() extends Diff
    case class Replace(l: Int, r: Int, i: Int) extends Diff

    def calc(i: Int): Diff = {
      var l, r = -1
      rep(A(i).length) { j =>
        if (A(i)(j) != B(i)(j)) {
          if (l == -1) l = j
          r = j
        }
      }
      if (r == -1) Same()
      else Replace(l, r + 1, i)
    }

    val diffs = map(N)(calc)
    var minS: String = ""
    var minT: String = ""
    var lastDiff: Option[Replace] = None
    var cntL, cntR = -1 // 左右の同じものが続く回数
    var ok = true
    rep(N) { i =>
      diffs(i) match {
        case Same() =>
        case replace @ Replace(l, r, _) =>
          val s = A(i).substring(l, r)
          val t = B(i).substring(l, r)
          if (minS.isEmpty) minS = s
          if (minT.isEmpty) minT = t

          // cntL, cntRはできるだけ広くとるほうがSameとバッティングしにくいので有利になる
          lastDiff match {
            case None =>
              lastDiff = Some(replace)
              cntL = l
              cntR = A(i).length - r

            case Some(last: Replace) =>
              var j = 1
              val A0 = A(i)
              val A1 = A(last.i)
              val B0 = B(i)
              val B1 = B(last.i)
              while(l - j >= 0 && j <= cntL && A0(l - j) == A1(last.l - j) && B0(l - j) == B1(last.l - j)) {
                j += 1
              }
              cntL = j - 1

              j = 0
              while(r + j < A0.length && j < cntR && A0(r + j) == A1(last.r + j) && B0(r + j) == B1(last.r + j)) {
                j += 1
              }
              cntR = j
          }

          lastDiff = Some(replace)
          ok &&= minS == s && minT == t
      }
    }

    val Some(last: Replace) = lastDiff
    val s = A(last.i).substring(last.l - cntL, last.r + cntR)
    val t = B(last.i).substring(last.l - cntL, last.r + cntR)

    rep(N) { i =>
      if (diffs(i) == Same()) {
        val ix = A(i).indexOf(s)
        ok &&= ix == -1 || {
          B(i).substring(ix, ix + s.length) == t
        }
      }
    }

    if (!ok) {
      out.println("NO")
    } else {
      out.println("YES")
      out.println(s)
      out.println(t)
    }
  }

  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)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

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

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

object 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 N = ni()
    val A, B = Array.ofDim[String](N)
    rep(N) { i =>
      A(i) = ns()
    }
    rep(N) { i =>
      B(i) = ns()
    }

    sealed trait Diff
    case class Same() extends Diff
    case class Replace(l: Int, r: Int, i: Int) extends Diff

    def calc(i: Int): Diff = {
      var l, r = -1
      rep(A(i).length) { j =>
        if (A(i)(j) != B(i)(j)) {
          if (l == -1) l = j
          r = j
        }
      }
      if (r == -1) Same()
      else Replace(l, r + 1, i)
    }

    val diffs = map(N)(calc)
    var minS: String = ""
    var minT: String = ""
    var lastDiff: Option[Replace] = None
    var cntL, cntR = -1 // 左右の同じものが続く回数
    var ok = true
    rep(N) { i =>
      diffs(i) match {
        case Same() =>
        case replace @ Replace(l, r, _) =>
          val s = A(i).substring(l, r)
          val t = B(i).substring(l, r)
          if (minS.isEmpty) minS = s
          if (minT.isEmpty) minT = t

          // cntL, cntRはできるだけ広くとるほうがSameとバッティングしにくいので有利になる
          lastDiff match {
            case None =>
              lastDiff = Some(replace)
              cntL = l
              cntR = A(i).length - r

            case Some(last: Replace) =>
              var j = 1
              val A0 = A(i)
              val A1 = A(last.i)
              val B0 = B(i)
              val B1 = B(last.i)
              while(l - j >= 0 && j < cntL && A0(l - j) == A1(last.l - j) && B0(l - j) == B1(last.l - j)) {
                j += 1
              }
              cntL = j - 1

              j = 0
              while(r + j < A0.length && j < cntR && A0(r + j) == A1(last.r + j) && B0(r + j) == B1(last.r + j)) {
                j += 1
              }
              cntR = j
          }

          lastDiff = Some(replace)
          ok &&= minS == s && minT == t
      }
    }

    val Some(last: Replace) = lastDiff
    val s = A(last.i).substring(last.l - cntL, last.r + cntR)
    val t = B(last.i).substring(last.l - cntL, last.r + cntR)

    rep(N) { i =>
      if (diffs(i) == Same()) {
        val ix = A(i).indexOf(s)
        ok &&= ix == -1 || {
          B(i).substring(ix, ix + s.length) == t
        }
      }
    }

    if (!ok) {
      out.println("NO")
    } else {
      out.println("YES")
      out.println(s)
      out.println(t)
    }
  }

  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)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

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

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

object D 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 as, bs = Array.fill(n){ readLine }

  var maxD, maxDPos = -1

  for (i <- 0 until n) {
    if (as(i) != bs(i)) {
      val a = as(i)
      val b = bs(i)
      var l = 0
      while (a(l) == b(l)) l += 1
      var r = a.length - 1
      while (a(r) == b(r)) r -= 1
      if (r - l > maxD) {
        maxD = r - l
        maxDPos = i
      }
    }
  }

  val a = as(maxDPos)
  val b = bs(maxDPos)
  var l = 0
  while (a(l) == b(l)) l += 1
  var r = a.length - 1
  while (a(r) == b(r)) r -= 1

  val s = a.substring(l, r + 1)
  val t = b.substring(l, r + 1)

  var ok = true
  for (i <- 0 until n) {
    if (ok) {
      val pos = as(i).indexOfSlice(s)
      val mod = if (pos < 0) as(i)
      else as(i).patch(pos, t, t.length)
      if (mod != bs(i)) ok = false
    }
  }

  if (ok) {
    println("YES")
    println(s)
    println(t)
  } else println("NO")
}


import java.util.Scanner

import scala.io.StdIn

object Atask560 extends App {
  var line = new Scanner(StdIn.readLine())
  val n = line.nextInt()
  val x = line.nextInt()
  val y = line.nextInt()
  line = new Scanner(StdIn.readLine())
  val digit = line.next.chars().toArray

  var result = 0

  for (i <- 0 until x) {
    if (digit(n - 1 - i) == '1' && y != i) {
      digit(n - 1 -i) = '0'
      result += 1
    }
    if (digit(n - 1 - i) == '0' && y == i) {
      digit(n - 1 -i) = '1'
      result += 1
    }
  }

  println(result)
}

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

  override def apply(io: IO): io.type = {
    val _, x, y = io.read[Int]
    val num = io.read[String].reverse.padTo(x, '0')

    val target = Array.fill(x)('0')
    target(y) = '1'

    val ans = num.zip(target).count({case (i, j) => i != j})

    io.write(ans)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

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

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

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

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

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

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

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

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

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }

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

object Main extends CodeForcesApp {

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

  override def apply(io: IO): io.type = {
    val _, x, y = io.read[Int]
    val num = io.read[String].reverse

    val target = Array.fill(x)('0')
    target(y) = '1'

    val ans = num.zip(target).count({ case (i, j) => i != j })

    io.write(ans)
  }
}

/** **************************[Ignore Template Below] ****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)

  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)

  def apply(io: IO): io.type

  def main(args: Array[String]): Unit = this (new IO(System.in, System.out)).close()
}

/** *********************************[Scala I/O] *********************************************/

import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

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

  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

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

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

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)

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

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)

  def readTillEndOfLine(): String = readTill("\n\r")

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

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

  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }

  def writeLine(): this.type = {
    printer.println()
    this
  }

  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }

  def writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = "\n")

  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)

  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()

  def close() = {
    flush()
    in.close()
    printer.close()
  }
}

object IO {

  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }

  object Read {
    implicit def collection[C[_], A: Read](implicit b: CanBuild[A, C[A]]): Read[C[A]] = new Read(r => r.read[C, A](r.read[Int]))

    implicit val string: Read[String] = new Read(_.next())
    implicit val int: Read[Int] = string.map(_.toInt)
    implicit val long: Read[Long] = string.map(_.toLong)
    implicit val bigInt: Read[BigInt] = string.map(BigInt(_))
    implicit val double: Read[Double] = string.map(_.toDouble)
    implicit val bigDecimal: Read[BigDecimal] = string.map(BigDecimal(_))

    implicit def tuple2[A: Read, B: Read]: Read[(A, B)] = new Read(r => (r.read[A], r.read[B]))

    implicit def tuple3[A: Read, B: Read, C: Read]: Read[(A, B, C)] = new Read(r => (r.read[A], r.read[B], r.read[C]))

    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]: Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))

    implicit val boolean: Read[Boolean] = string map { s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }

}


/**
 * Created by slie742 on 9/09/2015.
 */

import scala.io.StdIn.readLine
import scala.io.StdIn.readInt

import Math.abs
import Math.max
import Math.min

object DividingOrange {

  def readInts() : Array[Int] =
    readLine.split(' ').map(_.toInt)

  def readLongs() : Array[Long] =
    readLine.split(' ').map(_.toLong)

  def readTuple() : (Int,Int) = {
    val line = readInts
    (line(0),line(1))
  }
  def readTupleLong() : (Long,Long) = {
    val line = readLongs
    (line(0),line(1))
  }

  def readTriple() : (Int,Int,Int) = {
    val line = readInts
    (line(0),line(1),line(2))
  }
  def readQuad() : (Int,Int,Int,Int) = {
    val line = readInts
    (line(0),line(1),line(2),line(3))
  }

  def divideOranges(n: Int, k: Int, as: IndexedSeq[Int]) : List[List[Int]] = {
    def go(rem: List[Int], child: Int, acc: List[List[Int]]) : List[List[Int]] = {
        if (child == k) acc.reverse
        else {
          go(rem.drop(n-1), child + 1,(as(child) :: rem.take(n-1))  :: acc)
        }
    }
    go( ((1 to n*k).toSet[Int] -- as).toList , 0, List())
  }

  def main(args: Array[String]) {
    val (n,k) = readTuple()
    val as = readInts()
    println(divideOranges(n,k,as).map(_.mkString(" ")).mkString("\n"))

  }

}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P244A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N, K = sc.nextInt
  val A = List.fill(K)(sc.nextInt)

  def solve(): List[List[Int]] = {
    val segments = List.range(1, N * K + 1)
    val rest = segments.toSet -- A.toSet

    @tailrec
    def loop(acc: List[List[Int]], requests: List[Int], rest: List[Int]): List[List[Int]] = {
      if (requests == Nil) acc
      else loop(acc ++ List(requests.head :: rest.take(N - 1)), requests.tail, rest.drop(N - 1))
    }

    loop(Nil, A, rest.toList)
  }

  solve.foreach { lst =>
    out.println(lst.mkString(" "))
  }
  out.close
}

object Apelsin extends App {
    var ss = (Console.readLine.split(" ")) map (_.toInt)
    val (n,k) = (ss(0), ss(1))
    val aa0 = (Console.readLine.split(" ")) map (_.toInt)
    val aa = aa0 map (x => x-1)
    val nk = n*k
    var dl = Array.fill(nk)(0)

    def iniFill() = {
      for {
        i <- Range(0, k)
        j <- Range(0, n)
        val idx = n*i+j
      } dl(idx) = i
    }

    def printOneDol(i:Int) = {
      for {
        j <- Range(0, nk)
        if dl(j) == i
      } print((j+1) + " ")
      println
    }

    def printDl = {
      for {
        i <- Range(0, k)
      } printOneDol(i)
    }

    def findI(i:Int):Int = {
      val seq = for {
        ii <- Range(0, nk)
        if dl(ii) == i
      } yield ii
      seq(0)
    }

    def fixOne(i:Int, ai:Int) = {
      val idx = findI(i)
      if (ai != idx) {
        dl(idx) = dl(ai)
        dl(ai) = i
      }
    }

    def fixAll = {
      for {
        i<- Range(0, k)
      } fixOne(i, aa(i))
    }

    iniFill()
    fixAll
    printDl
}

import java.io._

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readLine = reader.readLine
  def readInt = readLine.toInt
  def split = readLine.split(" ")
  def readInts = split.map(_.toInt)

  val Array(n, k) = readInts
  val a = readInts
  def ans = if(n == 1) {
    a.mkString(" ")
  } else {
    (1 to n * k).filterNot(a.contains).grouped(n - 1).toArray.zip(a).map(x => (x._1 ++ Array(x._2)).mkString(" ")).mkString("\n")
  }

  def main(args: Array[String]) {
    println(ans)
  }
}

object Main {
  def main(args: Array[String]) = {
    val nk = readLine().split(" ").map(_.toInt)
    val n = nk(0)
    val k = nk(1)
    val a = readLine().split(" ").map(_.toInt)
    val s = scala.collection.mutable.Set() ++ (1 to n * k)
    s --= a

    if (n == 1) {
      for(i <- 0 until k) println(a(i))
    } else {
      s.grouped(n - 1).zipWithIndex.foreach { t =>
        println((t._1 ++ List(a(t._2))).mkString(" "))
      }
    }
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val data = in.next().split(" ").map(_.toInt)
  val set = data.toSet
  var j = 0

  val res = (0 until k).map{ i =>
    (2 to n).foldLeft(List(data(i))) {
      case(list, _) =>
        j += 1
        while (set.contains(j))
          j += 1
        j :: list
    }
  }
  println(res.map(_.mkString(" ")).mkString("\n"))
}

import java.io._

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readLine = reader.readLine
  def readInt = readLine.toInt
  def split = readLine.split(" ")
  def readInts = split.map(_.toInt)

  val Array(n, k) = readInts
  val a = readInts
  def ans = if(n == 1) {
    (1 to k).mkString(" ")
  } else {
    (1 to n * k).filterNot(a.contains).grouped(n - 1).toArray.zip(a).map(x => (x._1 ++ Array(x._2)).mkString(" ")).mkString("\n")
  }

  def main(args: Array[String]) {
    println(ans)
  }
}


import annotation.tailrec
import java.io._

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readInt = reader.readLine().toInt

  def ans = (for (_ <- 1 to readInt) yield if (360 % (180 - readInt) == 0) "YES" else "NO").mkString("\n")

  def main(args: Array[String]) {
    println(ans)
  }
}

object main extends App with fastIO {

  (1 to nextInt) foreach { (t) => println(if (360 % (180 - nextInt) == 0) "YES" else "NO") }

  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile)new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken()
    in.sval
  }

  def nextInt: Int = {
    in.nextToken()
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken()
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken()
    in.nval
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush() = out.flush()
}

object main extends App with fastIO {

  def check(n: Int) = { if (360 % n != 0) 0 else 180 - 360 / n }

  (1 to nextInt) foreach { (t) =>
    var f = false
    var angle = nextInt
    for (n <- 1 to 360)
      f = f || check(n) == angle
    println(if (f) "YES" else "NO")
  }

  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile)new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken()
    in.sval
  }

  def nextInt: Int = {
    in.nextToken()
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken()
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken()
    in.nval
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush() = out.flush()
}

object A{
    def main(args:Array[String]){
        val n=readLine.toInt

        for(_<-1 to n){
            val a=readLine.toInt
            if(360%(180-a)==0){
                println("YES")
            }else{
                println("NO")
            }
        }
    }
}

object cf165a extends App {
  val t = readLine.toInt
  (1 to t).map { qq =>
     val n = readLine.toInt
     println(if ((3 to 360).filter(i => 180 * (i - 2) == n * i).isEmpty) "NO" else "YES")
  }
}

object A {
	def main(args: Array[String]) {
		val n = readInt()

		for (i <- 1 to n) {
			val alpha = readInt()
			println(if (360 % (180 - alpha) == 0) "YES" else "NO")
		}
	}
}

object CF270A {
    def main(argv: Array[String]) {
        def judge(n: Int) {
            if (n > 0) {
                if (360 % (180 - readLine.toInt) == 0) println("YES")
                else println("NO")
                judge(n - 1)
            }
        }
        judge(readLine.toInt)
    }
}

import java.util.StringTokenizer

object _270A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  for (t <- 1 to next.toInt) {
    val a = next.toInt
    if (360 % (180 - a) == 0) println("YES")
    else println("NO")
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val t = in.next().toInt
  Range(0, t).foreach { _ =>
    val a = in.next().toInt
    if (360 % (180 - a) == 0) println("YES")
    else println("NO")

  }
}

object Main {
  def main(args : Array[String]) = {
    val t = readLine.toInt
    for(i <- 1 to t) {
      val a = readLine.toInt
      val ans = (3 to 1000).view.map({n => a * n == 180 * (n - 2)}).dropWhile(!_).isEmpty
      if(ans) println("NO") else println("YES")
    }
  }
}

object A270 extends App {
  val k = readLine.toInt

  for (a <- 1 to k) {
    val a = readLine.toInt
    var n: Int = 3
    var isSolve = false

    if (a < 60) {
      println("NO")
      isSolve = true
    }

    while (n < 1000 && !isSolve) {
      if (a * n == (n - 2) * 180) {
        println("YES")
        isSolve = true
      } else {
        n += 1
      }
    }
    if (!isSolve)
      println("NO")
  }

}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P270A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  def solve(): String = if (360 % (180 - sc.nextInt) == 0) "YES"
                        else "NO"

  for (i <- 0 until N)
    out.println(solve)
 out.close
}

object Main extends App {
	    def judge(n: Int) {
	        if (n > 0) {
		        if (360 % (180 - readLine.toInt) == 0) println("YES")
		        else println("NO")
		        judge(n - 1)
	        }
	    }
	    judge(readLine.toInt)
	}

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

object A extends App {
  val cin = new Scanner(new BufferedInputStream(System.in))
  for (i <- 0 until cin.nextInt) {
    var tak = false
    val n = cin.nextInt
    for (i <- 3 to 360)
      if (360 % i == 0 && 180 - 360 / i == n) {
        println("YES")
        tak = true
      }
    if (! tak) println("NO")
  }
}

import java.util._

object Test {

    def main(args: Array[String]) {
        val in = new Scanner(System.in)
        var n = in.nextInt
        for (i <- 0 to n - 1) {
            if (check(in.nextInt)) {
                println("YES")
            } else {
                println("NO")
            }
        }
    }

    def check(a: Int): Boolean = {
        val azChange = 180 - a
        val sides = 360 / azChange
        sides * azChange == 360
    }

}

import scala.io.Source

object test6 extends App {
    val t=readLine.toInt
    for(i<-1 to t){
        val a=readLine.toInt
        println(if(360%(180-a)==0) "YES" else "NO")
    }

}

import scala.io.Source

object test6 extends App {
    val t=readInt
    for(i<-1 to t){
        val a=readInt
        println(if(360%(180-a)==0) "YES" else "NO")
    }

}

object Main {
  val angles: Stream[Double] = {
    def angle(n: Int): Stream[Double] = {
      (180.0 * (n - 2) / n) #:: angle(n + 1)
    }
    angle(3)
  }

  def main(args: Array[String]) {
    val num = readInt()
    for(_ <- 1 to num) {
      val a = readInt()
      if (angles.takeWhile(_ <= a).filter(_ == a).size == 1) println("YES")
      else println("NO")
    }
  }
}

object FancyFence extends App {

  val t = readInt //num tests

  for (i <- Range(0, t)) {
    checkAngle(readDouble)
  }

  def checkAngle(angle: Double) {
    var sides = 2 / (1 - (angle / 180))
    if (Math.abs(sides - Math.round(sides)) < 0.000000001) {
      println("YES")
    } else {
      println("NO")
    }
  }

}

object cf165a extends App {
  val t = readLine.toInt
  (1 to t).map { qq =>
     val n = readLine.toInt
     println(if ((3 to 180).filter(i => 180 * (i - 2) == n * i).isEmpty) "NO" else "YES")
  }
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P270A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  val N = sc.nextInt
  val a = Array.fill(N)(sc.nextInt)

  def solve(x: Int): String =
    if (x >= 60 && 360 % x == 0) "YES"
    else "NO"

  for (i <- 0 until N)
    out.println(solve(a(i)))

  out.close
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P270A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  val N = sc.nextInt
  val a = Array.fill(N)(sc.nextInt)

  def solve(x: Int): String =
    if (x >= 60 && (360 % x == 0 || 360 % (180 - x) == 0)) "YES"
    else "NO"

  for (i <- 0 until N)
    out.println(solve(a(i)))

  out.close
}

import scala.math.BigDecimal

object FancyFence extends App {

  val t = readInt //num tests

  for (i <- Range(0, t)) {
    val angle = BigDecimal(readLine)
    val sides = 2.0 / (1.0 - (angle / 180.0))
    if ((sides - sides.intValue) == 0) {
      println("YES")
    } else {
      println("NO")
    }
  }

}

import scala.math.BigDecimal

object FancyFence extends App {

  val t = readInt //num tests

  for (i <- Range(0, t)) {
    val angle = BigDecimal(readLine)
    val sides = 2.0 / (1.0 - (angle / 180.0))
    println(sides)
    if ((sides - sides.intValue) == 0) {
      println("YES")
    } else {
      println("NO")
    }
  }

}

import scala.collection.immutable.HashMap

object FancyFence extends App {

  val t = readInt //num tests

  var set = Set[Int]()
  var n = 3
  var angle = ((n - 2) * 180) / n
  while (angle < 179) {
    set = set + angle
    n += 1
    angle = ((n - 2) * 180) / n
  }

//  println(set)

  for (i <- Range(0, t)) {
    val angle = readInt
    val sides = 2.0 / (1.0 - (angle / 180.0))
    if (set.contains(angle)) {
      println("YES")
    } else {
      println("NO")
    }
  }

}

import scala.collection.immutable.HashMap

object FancyFence extends App {

  val t = readInt //num tests

  var set = Set[Int]()
  var n = 3
  var angle = ((n - 2) * 180) / n
  while (angle < 179) {
    set = set + angle
    n += 1
    angle = ((n - 2) * 180) / n
  }

    println(set)

  for (i <- Range(0, t)) {
    val angle = readInt
    if (set.contains(angle)) {
      println("YES")
    } else {
      println("NO")
    }
  }

}

import scala.collection.immutable.HashMap

object FancyFence extends App {

  val t = readInt //num tests

  for (i <- Range(0, t)) {
    val angle = readInt
    val sides = 2.0 / (1.0 - (angle / 180.0))
    if (sides.isWhole()) {
      println("YES")
    } else {
      println("NO")
    }
  }

}

object A{
    def main(args:Array[String]){
        val n=readLine.toInt

        for(_<-1 to n){
            val a=readLine.toInt
            if(180%(180-a)==0 || 180%a==0){
                println("YES")
            }else{
                println("NO")
            }
        }
    }
}

object A{
    def main(args:Array[String]){
        val n=readLine.toInt

        for(_<-1 to n){
            val a=readLine.toInt
            if(180%(180-a)==0){
                println("YES")
            }else{
                println("NO")
            }
        }
    }
}


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

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

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

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

    case class node(val l: Int, val r: Int, val c: Char, var d: Boolean, var lc: Char, var mx: Char, var sz: Int){
    }

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

    val t = readInt()

    for (tt <- 1 to t) {
        val n = readInt()
        var ans = 0
        val arr = new Array[Boolean](210)
        for (i <- 1 to n) {
            val k = readInt()
            if (!arr(k+100)) {
                arr(k+100) = true
                ans += 1
            } else if (!arr(-1*k+100)) {
                arr(-1*k+100) = true
                ans += 1
            }
        }
        writer.println(ans)

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

import scala.collection.mutable

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

    for (_ <- 1 to nextInt) {
      val n = nextInt
      val as = nextInts(n)
      val have = mutable.Set.empty[Int]

      for (a <- as) {
        if (!have(a)) {
          have += a
        } else if (!have(-a)) {
          have += -a
        }
      }

      out.println(have.size)
    }

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


//package scala_tutorial

import scala.collection.mutable._
object source {
	def main(args : Array[String]) {
		val Array(n, m) = readLine split " " map (_.toInt)
		var f = readLine split " " map (_.toInt)
		var b = readLine split " " map (_.toInt)

		val cnt = new HashMap[Int, Int]().withDefaultValue(0)
		val pos = new HashMap[Int, Int]().withDefaultValue(-1)

		var index = 0
		for(index <- 0 until n)
		{
			cnt(f(index))+=1
			pos(f(index))=index+1
		}
		var ambiguity = false
		for(index <- 0 until m)
		{
			if(cnt(b(index))==0)
			{
				println("Impossible")
				System.exit(0)
			}
			else if(cnt(b(index))>1)
			{
				ambiguity = true
			}
		}
		if(ambiguity)
		{
			println("Ambiguity")
		}
		else
		{
			println("Possible")
			println(b map (elem => pos(elem)) mkString " ")
		}
	}
}

//package scala_tutorial

import scala.collection.mutable._
object source {
	def main(args : Array[String]) {
		val Array(n, m) = readLine split " " map (_.toInt)
		var f = readLine split " " map (_.toInt)
		var b = readLine split " " map (_.toInt)
		var index = 0
		var imap = new HashMap[Int, Int]
		var cnt = new HashMap[Int, Int]().withDefaultValue(0)
		var ret = 0
		var ans = Array.ofDim[Int](m+1)
		for (index <- 0 until n)
		{
			cnt(f(index))+=1
			imap(f(index))=index+1
		}
		for (index <- 0 until m)
		{
			if(imap.contains(b(index))==false)
			{
				println("Impossible")
				System.exit(0)
			}
			else
			{
				if(cnt(b(index))>1)
				{
					ret = 1
				}
				else
				{
					ans(index)=imap(b(index))
				}
			}
		}
		if(ret == 1)println("Ambiguity")
		else
		{
			println("Possible")
			for (index <- 0 until m)
			{
				printf("%d ", ans(index))
			}
		}

	}
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(' ').map(_.toInt)
  val f = in.next().split(' ').map(_.toInt)
  val b = in.next().split(' ').map(_.toInt)
  val map = f.indices.foldLeft(Map.empty[Int, Set[Int]]) {
    case (m, i) =>
      val value = f(i)
      if (m.contains(value))
        m + (value -> (m(value) + (i + 1)))
      else
        m + (value -> Set(i + 1))
  }

  val res = b.foldLeft((0, List.empty[Int])) {
    case ((2, _), _) => (2, Nil)
    case (_, el) if !map.contains(el) => (2, Nil)
    case ((1, _), el) => (1, Nil)
    case (_, el) if map(el).size > 1 => (1, Nil)
    case ((0, list), el) => (0, map(el).head :: list)
  }
  if (res._1 == 0) {
    println("Possible")
    println(res._2.reverse.mkString(" "))
  }
  else if (res._1 == 1)
    println("Ambiguity")
  else
    println("Impossible")
}

import scala.collection._

object B extends App {

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

  val Array(n, m) = readInts(2)
  val fs = readInts(n)
  val bs = readInts(m)

  val fCnts = Array.fill(n + 1){ 0 }
  for (f <- fs) fCnts(f) += 1

  for (b <- bs) if (fCnts(b) == 0) {
    println("Impossible")
    System.exit(0)
  }

  for (b <- bs) if (fCnts(b) > 1) {
    println("Ambiguity")
    System.exit(0)
  }

  val bToA = fs.zipWithIndex.toMap.mapValues(_ + 1)
  val as = bs.map(bToA)

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

  println("Possible")
  println(as.mkString(" "))

  Console.flush
}

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

object _599B extends CodeForcesApp {
  override type Result = String

  override def solve(scanner: Scanner) = {
    import scanner._
    val (n, m) = (nextInt(), nextInt())
    val f = Seq.tabulate(n)(i => nextInt() -> (i+1)).toMultiMap
    val b = Seq.fill(m)(nextInt())

    var result: Option[String] = None

    val ans = b map {i =>
      f get i match {
        case None | Some(Nil) =>
          result = Some("Impossible")
          0
        case Some(_ :: _ :: _) =>
          if (!(result contains "Impossible")) result = Some("Ambiguity")
          0
        case Some(x :: Nil) =>
          x
      }
    }

    result getOrElse ans.mkString("Possible\n", " ", "")
  }

  implicit class PairsExtensions[A, B](t: Traversable[(A, B)]) {
    def toMultiMap: Map[A, List[B]] = t.groupBy(_._1).mapValues(_.map(_._2).toList)
  }
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val mod: Int = 1000000007
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String = result.toString
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
 * Scala implementation of a faster java.util.Scanner
 * See: http://codeforces.com/blog/entry/21125
 * All next methods throw NoSuchElementException when !hasNext
 */
class Scanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))
  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))
  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)
  def this(str: String) = this(new StringReader(str))

  val lines = Iterator.continually(reader.readLine()).takeWhile(_ != null) //TODO: In Java 8 reader.lines().iterator

  private[this] val tokenizers = lines.map(new StringTokenizer(_)).filter(_.hasMoreTokens)
  private[this] var current: Option[StringTokenizer] = None

  @inline private[this] def tokenizer(): Option[StringTokenizer] = current.find(_.hasMoreTokens) orElse {
    current = if (tokenizers.hasNext) Some(tokenizers.next()) else None
    current
  }

  /**
   * Unlike Java's scanner which returns till end of current line, this actually returns the next line
   * @see line() if you want the Java behaviour
   */
  def nextLine(): String = {
    current = None   // reset
    lines.next()
  }
  def lineNumber: Int = reader.getLineNumber
  def line(): String = tokenizer().get.nextToken("\n\r")
  def nextString(): String = next()
  def nextChar(): Char = next().ensuring(_.length == 1).head
  def nextBoolean(): Boolean = next().toBoolean
  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)
  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)
  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)
  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)
  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)
  def nextFloat(): Float = next().toFloat
  def nextDouble(): Double = next().toDouble
  def nextBigDecimal(): BigDecimal = BigDecimal(next())
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

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

object _599B extends CodeForcesApp {
  override type Result = String

  override def solve(scanner: Scanner) = {
    import scanner._
    val (n, m) = (nextInt(), nextInt())
    val f = Seq.tabulate(n)(i => nextInt() -> (i+1)).toMultiMap withDefaultValue Nil
    val b = Seq.fill(m)(nextInt())

    var result: Option[String] = None

    val ans = b map f map {
      case Nil => result = Some("Impossible"); 0
      case x :: Nil =>  x
      case _ =>
        if (!(result contains "Impossible")) result = Some("Ambiguity")
        0
    }

    result getOrElse ans.mkString("Possible\n", " ", "")
  }

  implicit class PairsExtensions[A, B](t: Traversable[(A, B)]) {
    def toMultiMap: Map[A, List[B]] = t.groupBy(_._1).mapValues(_.map(_._2).toList)
  }
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val mod: Int = 1000000007
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String = result.toString
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
 * Scala implementation of a faster java.util.Scanner
 * See: http://codeforces.com/blog/entry/21125
 * All next methods throw NoSuchElementException when !hasNext
 */
class Scanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))
  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))
  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)
  def this(str: String) = this(new StringReader(str))

  val lines = Iterator.continually(reader.readLine()).takeWhile(_ != null) //TODO: In Java 8 reader.lines().iterator

  private[this] val tokenizers = lines.map(new StringTokenizer(_)).filter(_.hasMoreTokens)
  private[this] var current: Option[StringTokenizer] = None

  @inline private[this] def tokenizer(): Option[StringTokenizer] = current.find(_.hasMoreTokens) orElse {
    current = if (tokenizers.hasNext) Some(tokenizers.next()) else None
    current
  }

  /**
   * Unlike Java's scanner which returns till end of current line, this actually returns the next line
   * @see line() if you want the Java behaviour
   */
  def nextLine(): String = {
    current = None   // reset
    lines.next()
  }
  def lineNumber: Int = reader.getLineNumber
  def line(): String = tokenizer().get.nextToken("\n\r")
  def nextString(): String = next()
  def nextChar(): Char = next().ensuring(_.length == 1).head
  def nextBoolean(): Boolean = next().toBoolean
  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)
  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)
  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)
  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)
  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)
  def nextFloat(): Float = next().toFloat
  def nextDouble(): Double = next().toDouble
  def nextBigDecimal(): BigDecimal = BigDecimal(next())
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

import scala.io.StdIn._

object B extends App {
  val Array(n, m) = readLine().split(" ").map(_.toInt)
  val F = readLine().split(" ").map(_.toInt)
  val B = readLine().split(" ").map(_.toInt)

  val Bcounter = Array.ofDim[Int](n + 1)
  val Fcounter = Array.ofDim[Int](n + 1)

  B.foreach(x => Bcounter(x) += 1)
  F.foreach(x => Fcounter(x) += 1)

  if (B.exists(x => Fcounter(x) == 0)) {
    println("Impossible")
  } else if (B.exists(x => Fcounter(x) > 1)) {
    println("Ambiguity")
  } else {
    println("Possible")
    val M = F.zipWithIndex.map {
      x => (x._1, x._2 + 1)
    }.toMap

    println(B.map(x => M(x)).mkString(" "))
  }

}

object B{
  //import scala.collection.mutable.PriorityQueue
  //import scala.collection.mutable.ArrayBuffer
  import util.control.Breaks._
  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}
  import java.util.{Locale, Scanner,StringTokenizer}
  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
        while (!st.hasMoreTokens()){
          val currentLine = reader.readLine
          st=new StringTokenizer(currentLine)
        }
        return st.nextToken
    }

    def nextInt():Int = {
        return next.toInt
    }

    def nextLong():Long = {
    	return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]){

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = in.next
    //code starts here
    val (n,m)=(nextInt,nextInt)
    val ft=Array.fill(n+1)(-1)
    for(i<-0 until n){
      val t=nextInt
      if(ft(t)== -1){
        ft(t)=i+1
      }else{
        ft(t)= -2
      }
    }
    var flag=0
    val a=Array.ofDim[Int](m)
    breakable{
      for(i<-0 until m){
        val b=nextInt
        if(ft(b)== -1){
          flag=2
          break
        }else if(ft(b)== -2&& flag!=2){
          flag=1

        }else{
          a(i)=ft(b)
        }
      }
    }
    if(flag==2){
      out.println("Impossible")
    }else if(flag==1){
      out.println("Ambiguity")

    }else{
      out.println("Possible")
      for(i<-0 until m-1){
        out.print(a(i)+" ")
      }
      out.println(a(m-1))
    }
    //code ends here
    out.flush
    out.close
  }
}

//package scala_tutorial

import scala.collection.mutable._
object source {
	def main(args : Array[String]) {
		val Array(n, m) = readLine split " " map (_.toInt)
		var f = readLine split " " map (_.toInt)
		var b = readLine split " " map (_.toInt)
		var index = 0
		var imap = new HashMap[Int, Int]
		var cnt = new HashMap[Int, Int]().withDefaultValue(0)
		var ret = 0
		var ans = Array.ofDim[Int](m+1)
		for (index <- 0 until n)
		{
			cnt(f(index))+=1
			imap(f(index))=index+1
		}
		for (index <- 0 until m)
		{
			if(imap.contains(b(index))==false)
			{
				ret = 2
			}
			else
			{
				if(cnt(b(index))>1)
				{
					ret = 1
				}
				else
				{
					ans(index)=imap(b(index))
				}
			}
		}
		if(ret == 1)println("Ambiguity")
		else if(ret == 2)println("Impossible")
		else
		{
			println("Possible")
			for (index <- 0 until m)
			{
				printf("%d ", ans(index))
			}
		}

	}
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(' ').map(_.toInt)
  val data1 = in.next().split(' ').map(_.toInt).sorted
  val data2 = in.next().split(' ').map(_.toInt).sorted
  val impossible = n != m
  val duplicates = (data1.distinct.length != data1.length) || (data2.distinct.length != data2.length)
  val res = data1.zip(data2).foldLeft(if (impossible) 2 else if (duplicates) 1 else 0) {
    case (2, _) => 2
    case (_, (el1, el2)) if el1 != el2 => 2
    case (status, _) => status
  }
  if (res == 0) {
    println("Possible")
    println(data1.mkString(" "))
  }
  else if (res == 1)
    println("Ambiguity")
  else
    println("Impossible")
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(' ').map(_.toInt)
  val data1unsorted = in.next().split(' ').map(_.toInt)
  val data1 = data1unsorted.sorted
  val data2 = in.next().split(' ').map(_.toInt).sorted
  val impossible = n != m
  val duplicates = (data1.distinct.length != data1.length) || (data2.distinct.length != data2.length)
  val res = data1.zip(data2).foldLeft(if (impossible) 2 else if (duplicates) 1 else 0) {
    case (2, _) => 2
    case (_, (el1, el2)) if el1 != el2 => 2
    case (status, _) => status
  }
  if (res == 0) {
    println("Possible")
    println(data1unsorted.mkString(" "))
  }
  else if (res == 1)
    println("Ambiguity")
  else
    println("Impossible")
}

import scala.io.StdIn._

object B extends App {
  val Array(n, m) = readLine().split(" ").map(_.toInt)
  val F = readLine().split(" ").map(_.toInt)
  val B = readLine().split(" ").map(_.toInt)

  val Bcounter = Array.ofDim[Int](n + 1)
  val Fcounter = Array.ofDim[Int](n + 1)

  B.foreach(x => Bcounter(x) += 1)
  F.foreach(x => Fcounter(x) += 1)

  if (F.exists(x => Bcounter(x) == 0)) {
    println("Impossible")
  } else if (B.exists(x => Fcounter(x) > 1)) {
    println("Ambiguity")
  } else {
    println("Possible")
    val M = F.zipWithIndex.map {
      x => (x._1, x._2 + 1)
    }.toMap

    println(B.map(M(_)).mkString(" "))
  }

}

import scala.io.StdIn._

object B extends App {
  val Array(n, m) = readLine().split(" ").map(_.toInt)
  val F = readLine().split(" ").map(_.toInt)
  val B = readLine().split(" ").map(_.toInt)

  val Bcounter = Array.ofDim[Int](n + 1)

  B.foreach(x => Bcounter(x) += 1)

  if (F.exists(x => Bcounter(x) == 0)) {
    println("Impossible")
  } else if (F.forall(x => Bcounter(x) == 1)) {
    println("Possible")
  } else {
    println("Ambiguity")
  }

}

object B{
  //import scala.collection.mutable.PriorityQueue
  //import scala.collection.mutable.ArrayBuffer
  import util.control.Breaks._
  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}
  import java.util.{Locale, Scanner,StringTokenizer}
  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
        while (!st.hasMoreTokens()){
          val currentLine = reader.readLine
          st=new StringTokenizer(currentLine)
        }
        return st.nextToken
    }

    def nextInt():Int = {
        return next.toInt
    }

    def nextLong():Long = {
    	return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]){

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = in.next
    //code starts here
    val (n,m)=(nextInt,nextInt)
    val f=(for(i<-0 until n) yield (nextInt,i+1)) sorted
    val a=Array.ofDim[Int](m)
    var flag=0
    breakable{
      for(i<-0 until m){
        val b=nextInt
        var l=0
        var r=n-1
        while(l<r-1){
          val c=(l+r)/2
          if(f(c)._1>b){
            r=c
          }else{
            l=c
          }
        }
        var ma= -1
        if(f(l)._1==b){
          ma=l
        }else if(f(r)._1==b){
          ma=r
        }else{
          flag=2
          break

        }
        if(ma>0 && f(ma-1)._1==b){
          flag=1
          break
        }
        if(ma<n-1 && f(ma+1)._1==b){
          flag=1
          break
        }
        a(i)=f(ma)._2
      }
    }
    if(flag==2){
      out.println("Impossible")
    }else if(flag==1){
      out.println("Ambiguity")

    }else{
      out.println("Possible")
      for(i<-0 until m){
        out.print(a(i)+" ")
      }
    }
    //code ends here
    out.flush
    out.close
  }
}

object B{
  //import scala.collection.mutable.PriorityQueue
  //import scala.collection.mutable.ArrayBuffer
  import util.control.Breaks._
  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}
  import java.util.{Locale, Scanner,StringTokenizer}
  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
        while (!st.hasMoreTokens()){
          val currentLine = reader.readLine
          st=new StringTokenizer(currentLine)
        }
        return st.nextToken
    }

    def nextInt():Int = {
        return next.toInt
    }

    def nextLong():Long = {
    	return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]){

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = in.next
    //code starts here
    val (n,m)=(nextInt,nextInt)
    val ft=Array.fill(n+1)(-1)
    for(i<-0 until n){
      val t=nextInt
      if(ft(t)== -1){
        ft(t)=i+1
      }else{
        ft(t)= -2
      }
    }
    var flag=0
    val a=Array.ofDim[Int](m)
    breakable{
      for(i<-0 until m){
        val b=nextInt
        if(ft(b)== -1){
          flag=2
          break
        }else if(ft(b)== -2){
          flag=1
          break
        }else{
          a(i)=ft(b)
        }
      }
    }
    if(flag==2){
      out.println("Impossible")
    }else if(flag==1){
      out.println("Ambiguity")

    }else{
      out.println("Possible")
      for(i<-0 until m-1){
        out.print(a(i)+" ")
      }
      out.println(a(m-1))
    }
    //code ends here
    out.flush
    out.close
  }
}

object B{
  //import scala.collection.mutable.PriorityQueue
  //import scala.collection.mutable.ArrayBuffer
  import util.control.Breaks._
  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}
  import java.util.{Locale, Scanner,StringTokenizer}
  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
        while (!st.hasMoreTokens()){
          val currentLine = reader.readLine
          st=new StringTokenizer(currentLine)
        }
        return st.nextToken
    }

    def nextInt():Int = {
        return next.toInt
    }

    def nextLong():Long = {
    	return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]){

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = in.next
    //code starts here
    val (n,m)=(nextInt,nextInt)
    val ft=Array.fill(n+1)(-1)
    for(i<-0 until n){
      val t=nextInt
      if(ft(t)== -1){
        ft(t)=i+1
      }else{
        ft(t)= -2
      }
    }
    var flag=0
    val a=Array.ofDim[Int](m)
    breakable{
      for(i<-0 until m){
        val b=nextInt
        if(ft(b)== -1){
          flag=2
          break
        }else if(ft(b)== -2){
          flag=1
          break
        }else{
          a(i)=ft(b)
        }
      }
    }
    if(flag==2){
      out.println("Impossible")
    }else if(flag==1){
      out.println("Ambiguity")

    }else{
      out.println("Possible")
      for(i<-0 until m){
        out.print(a(i)+" ")
      }
    }
    //code ends here
    out.flush
    out.close
  }
}