use std::collections::VecDeque;


fn solve() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let mut a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut not_checked = (1..=n).collect::<VecDeque<usize>>();
    while not_checked.len() > 1 {
        let front = not_checked[0];
        let back = not_checked[not_checked.len()-1];
        if a[front-1] != front || a[back+n-1] != back {
            break;
        }
        if a[front+n-1] == a[front-1] && a[back-1] == a[back+n-1] {
            not_checked.pop_back();
            not_checked.pop_front();
        } else if a[front+n-1] != a[front-1] && a[back-1] != a[back+n-1] {
            break;
        } else if a[front+n-1] != a[front-1] {
            a[back-1..=back+n-1].reverse();
            not_checked.pop_back();
        } else {
            a[front-1..=front+n-1].reverse();
            not_checked.pop_front();
        }
    }
    if (0..2*n).filter(|&i| (i%n)+1 != a[i]).count() == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let t: usize = t.trim().parse().unwrap();
    for _ in 0..t {
        solve();
    }
}