Each query is associated with the workbook used to create it and with the connection used by QMF Visionary Studio to connect to the data source. You can change a query's associations--either to its workbook or to its connection--with its context menu.
For example, you might develop a world using a test database, and then when the world is ready to be published, change the query associations to the data source for the production database.