import sequtils,strutils template times*(n:int,body) = (for _ in 0.." .} proc scan(): int = while true: var k = getchar_unlocked() if k < '0': break result = 10 * result + k.ord - '0'.ord let n = scan() let k = scan() let x = scan() var C = toSeq(1..n) var XC : seq[int] for ik in 1..k: if ik == x : XC = C 4.times : discard getchar_unlocked() continue let a = scan() - 1 let b = scan() - 1 swap(C[a],C[b]) let diff = C.filterIt(it != scan()) var answers = newSeq[int]() for i,xc in XC: if xc != diff[0] and xc != diff[1] : continue answers &= i + 1 if answers.len == 2: break echo answers.mapIt($it).join(" ")