// Author: @Drydock
use std::io::{self, Read};
fn main() {
solve();
}
fn solve() {
let mut input = String::new();
io::stdin().read_to_string(&mut input).unwrap();
let mut it = I::new(&input);
let t: usize = it.n();
let mut o = String::new();
for _ in 0..t {
let n: usize = it.n();
let s: String = it.n();
let p: String = it.n();
if s == p {
o.push_str("YES\n");
continue;
}
if n == 1 {
o.push_str("NO\n");
continue;
}
let b = p.as_bytes();
let mut z = true;
let c = b[0];
for &x in b.iter() {
if x != c {
z = false;
break;
}
}
if z {
o.push_str("NO\n");
} else {
o.push_str("YES\n");
}
}
print!("{o}");
}
struct I<'a> {
w: std::str::SplitWhitespace<'a>,
}
impl<'a> I<'a> {
fn new(s: &'a str) -> Self {
Self {
w: s.split_whitespace(),
}
}
fn n<T: std::str::FromStr>(&mut self) -> T {
self.w.next().unwrap().parse().ok().unwrap()
}
}