Which State returns given I worked in one State and lived in 2 others

Hi,

In 2020, I worked all year in Massachusetts and I lived in Rhode Island from January 1 to June 5 and then Connecticut from June 6 to December 31.  From my W2 I can see that I paid income Taxes in Massachusetts.

What type of State returns do I need?

 

Also, are the proceeds and costs associated with selling my Rhode Island home and buying a Connecticut home going to be accounted for on my Federal return and flow through to my RI and CT returns?

Best,

Tim