program rgb_balls
  implicit none
  integer(8), parameter :: md = 998244353_8
  integer :: n, i, j, k, cnt(3) = 0, x, y, z
  integer(8) :: ans = 1_8
  character(300000) :: s
  read(*,*) n
  read(*,*) s
  do i = 1, 3*n
    select case(s(i:i))
    case("R")
      j = 1
    case("G")
      j = 2
    case("B")
      j = 3
    end select
    x = minval(cnt)
    z = maxval(cnt)
    y = sum(cnt)-x-z
    if (cnt(j) == z) then
      cnt(j) = cnt(j)+1
    else if (cnt(j) == y) then
      ans = mod(ans*int(z-y,8),md)
      cnt(j) = cnt(j)+1
    else if (y == 0) then
      cnt(j) = cnt(j)+1
    else
      ans = mod(ans*int(y,8),md)
      do k = 1, 3
        if (k == j) cycle
        cnt(k) = cnt(k)-1
      end do
    end if
  end do
  do i = 1, n
    ans = mod(ans*int(i,8),md)
  end do
  write(*,'(i0)') ans
end program rgb_balls