import sequtils, strutils, tables let t = parseInt readLine stdin proc fn(): bool = let n = parseInt readLine stdin a = stdin.readLine.split.map parseInt cntT = a.toCountTable if a[0] != 1: return false if a[^1] != n: return false if cntT.largest.val != 2: return false if cntT.smallest.val != 2: return false for i in 1 .. a.high: let x = abs a[i] - a[pred i] if x notin {1, pred n}: return false return true for _ in 0 ..< t: echo if fn(): "Yes" else: "No"