pub mod scanner { pub struct Scanner { buf: Vec, } impl Scanner { pub fn new() -> Self { Self { buf: vec![] } } pub fn new_from(source: &str) -> Self { let source = String::from(source); let buf = Self::split(source); Self { buf } } pub fn next(&mut self) -> T { loop { if let Some(x) = self.buf.pop() { return x.parse().ok().expect(""); } let mut source = String::new(); std::io::stdin().read_line(&mut source).expect(""); self.buf = Self::split(source); } } fn split(source: String) -> Vec { source .split_whitespace() .rev() .map(String::from) .collect::>() } } } use std::collections::{BTreeMap, BTreeSet, BinaryHeap}; use crate::scanner::Scanner; fn main() { let mut scanner = Scanner::new(); let t: usize = scanner.next(); for _ in 0..t { solve(&mut scanner); } } fn solve(scanner: &mut Scanner) { let n: usize = scanner.next(); let m: usize = scanner.next(); let mut count = BTreeMap::new(); let a: Vec = (0..n) .map(|_| { let x = scanner.next::(); *count.entry(x).or_insert(0) += 1; x }) .collect(); let b: Vec = (0..m) .map(|_| { let x = scanner.next::(); *count.entry(x).or_insert(0) += 1; x }) .collect(); if n == 0 || m == 0 { println!("Yes"); if n == 0 { for i in 0..m { println!("Blue {}", b[i]); } } else { for i in 0..n { println!("Red {}", a[i]); } } return; } let mut c = BTreeSet::new(); let mut q = BinaryHeap::new(); for (&k, &v) in count.iter() { if v == 2 { c.insert(k); q.push(k); } } let c = c; if c.len() == 0 { println!("No"); return; } println!("Yes"); for i in 0..n { if c.contains(&a[i]) { continue; } else { println!("Red {}", a[i]); } } { let now = q.pop().unwrap(); println!("Red {}", now); println!("Blue {}", now); } for i in 0..m { if c.contains(&b[i]) { continue; } else { println!("Blue {}", b[i]); } } let mut turn = 1; while let Some(now) = q.pop() { if turn == 0 { println!("Red {}", now); println!("Blue {}", now); turn = 1; } else { println!("Blue {}", now); println!("Red {}", now); turn = 0; } } }