import sequtils, strutils proc solve(): bool = let n = parseInt readLine stdin a = stdin.readLine.split.map parseInt var l = 0 r = a.high x1 = 1 x2 = n if a[0] != 1: return false if a[^1] != n: return false for i in 1..a.high: let d = (a[i] - a[i.pred]).abs if d != 1 and d != n.pred: return false while a[l] == x1: inc l inc x1 while r >= 0 and a[r] == x2: dec r dec x2 while a[l] == x2: inc l dec x2 while r >= 0 and a[r] == x1: dec r inc x1 return l > r let t = parseInt readLine stdin for _ in 0 ..< t: echo if solve(): "Yes" else: "No"