J, 80 65 6169 bytes
1#.[:,1 2 3*#:@2 1 2*(3,:1,:3 3)((]-:*)#:@2 7 2);._3"2^:(<3)]
Try it online!
-15 thanks to inspiration I got after reading Neil's approach
There is currently a small bug in the 61 byte version. I'll fix it tomorrow -- meanwhile consider the other answer official.
original approach, 80 bytes
[:+/@,1 2 3*((,.@1;];[:,/[:,./"3#"{~)#:2 7 2)4 :'y([x-:*/@,:)&>/[:,(,.~3^/i.3x&*)<;;._3"$]_3~$x'&><
Try it online!Try it online!