macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        s: chars
    }
    let d = 998244353;
    let mut v = vec![(0, 0); 3 * n];
    let mut cr = 0;
    let mut cg = 0;
    let mut cb = 0;
    for i in 0..3 * n {
        if s[i] == 'R' {
            cr += 1;
            if cr > max(cg, cb) {
                v[i] = (0, 1);
            } else if cr <= min(cg, cb) {
                v[i] = (2, 1);
            } else if cg < cb {
                v[i] = (1, 312);    // B R G
            } else {
                v[i] = (1, 213);    // G R B
            }
        } else if s[i] == 'G' {
            cg += 1;
            if cg > max(cr, cb) {
                v[i] = (0, 2);
            } else if cg <= min(cr, cb) {
                v[i] = (2, 2);
            } else if cr < cb {
                v[i] = (1, 321);    // B G R
            } else {
                v[i] = (1, 123);    // R G B
            }
        } else {
            cb += 1;
            if cb > max(cr, cg) {
                v[i] = (0, 3);
            } else if cb <= min(cr, cg) {
                v[i] = (2, 3);
            } else if cr < cg {
                v[i] = (1, 231);    // G B R
            } else {
                v[i] = (1, 132);    // R B G
            }
        }
    }
    let mut pre: Vec<usize> = vec![];
    let mut pos: Vec<usize> = vec![];
    let mut count = vec![0, 0, 0, 0];
    for &(i, c) in &v {
        if i == 0 {
            count[c] += 1;
        } else if i == 1 {
            pre.push(count[c / 100]);
            count[c / 100] -= 1;
        }
    }
    count = vec![0, 0, 0, 0];
    for &(i, c) in v.iter().rev() {
        if i == 2 {
            count[c] += 1;
        } else if i == 1 {
            pos.push(count[c % 10]);
            count[c % 10] -= 1;
        }
    }
    pos.reverse();
    println!("{}", pre.iter().zip(pos.iter()).fold(stair_m(n, d), |ac, (a, b)| ac * a % d * b % d));
}

fn stair_m(n: usize, d: usize) -> usize {
    (1..n + 1).fold(1, |ac, x| ac * x % d)
}


Measured memory_bytes: 14588