// ---------- begin Run Length Encoding ---------- fn run_length_encoding(a: Vec) -> Vec<(T, usize)> { let mut a = a.into_iter().map(|a| (a, 1)).collect::>(); a.dedup_by(|a, b| { a.0 == b.0 && { b.1 += a.1; true } }); a } // ---------- end Run Length Encoding ---------- // ---------- begin scannner ---------- #[allow(dead_code)] mod scanner { use std::str::FromStr; pub struct Scanner<'a> { it: std::str::SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next(&mut self) -> T { self.it.next().unwrap().parse::().ok().unwrap() } pub fn next_bytes(&mut self) -> Vec { self.it.next().unwrap().bytes().collect() } pub fn next_chars(&mut self) -> Vec { self.it.next().unwrap().chars().collect() } pub fn next_vec(&mut self, len: usize) -> Vec { (0..len).map(|_| self.next()).collect() } } } // ---------- end scannner ---------- use std::io::Write; use std::collections::*; type Map = BTreeMap; type Set = BTreeSet; type Deque = VecDeque; fn main() { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = scanner::Scanner::new(&s); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); run(&mut sc, &mut out); } fn run(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter) { /* let mut map = Map::new(); map.insert(vec![1], vec![1f64]); map.insert(vec![0], vec![0f64]); for n in 2..20 { let mut a = vec![0; n]; for i in (0..n).step_by(2) { a[i] = 1; } for _ in 0..2 { let b = a.clone(); let mut s = vec![]; for i in 1..n { let (l, r) = b.split_at(i); let l = Vec::from(l); let r = Vec::from(r); let x = &map[&l]; let y = &map[&r]; for x in x.iter() { for y in y.iter() { s.push((*x + *y) * 0.5); } } } s.sort_by(|a, b| a.partial_cmp(b).unwrap()); s.dedup_by(|a, b| (*a - *b).abs() < 1e-9); if s.iter().any(|s| (*s - 0.5).abs() < 1e-9) { println!("{}: {:?}", n, b); } map.insert(b, s); a.iter_mut().for_each(|a| *a ^= 1); } } */ let t: u32 = sc.next(); for _ in 0..t { let n: usize = sc.next(); let a: Vec = sc.next_vec(n); let z = run_length_encoding(a); let ans = if z.len() >= 9 || z.len() % 2 == 0 || (z.len() % 2 == 1 && z.iter().any(|p| p.0 == z[1].0 && p.1 > 1)) { "Yes" } else { "No" }; writeln!(out, "{}", ans).ok(); } }