To be honest this is something that completely exceed my possibilities with JavaScript. Furthermore I don’t know if this is something possible to do directly on n8n. I tried to solve with nodes but obviously I couldn’t.
So does that mean the images are an example of what you expect to see in n8n and it isn’t something you want to do in Google Sheets? At the moment I am trying to work out what you are actually trying to do.