fn main() { let mut t = String::new(); std::io::stdin().read_line(&mut t).ok(); let t: usize = t.trim().parse().unwrap(); let base = vec![vec!["0", "1", "1"], vec!["1", "2", "2"], vec!["1", "2", "2"]]; for _ in 0..t { let mut hw = String::new(); std::io::stdin().read_line(&mut hw).ok(); let hw: Vec = hw.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let h = hw[0]; let w = hw[1]; let hstart = if h % 3 == 2 { 1 } else { 0 }; let wstart = if w % 3 == 2 { 1 } else { 0 }; for i in 0..h { let i = i + hstart; println!("{}", (wstart..wstart+w).map(|j| base[i%3][j%3]).collect::>().join(" ")); } } }