I worked at University A and did a research stay during one month at University B; I was not paid by them, but I got funding (from a third agency) thanks to them for accepting my visit during a salary gap, before going to University C.
About 80% of the paper I want to submit I wrote in my university, but I finished it at University B during said stay, even though my original aim of being at University B was another research topic.
I would like to put U A and U B both as affiliations, since the environment in U B boosted my research (and I don't want to be less thankful than I ought). Is it justified to write both affiliations? Or should I write only University A as affiliation and thank for hospitality to University B and my host there?