Use the print query result for a pretty SQL script
SET NOCOUNT ON
select
CONCAT('ALTER DATABASE [',name,'] SET QUERY_STORE = ON',char(10),'GO',char(10),
'ALTER DATABASE [',name,'] SET QUERY_STORE (OPERATION_MODE = READ_WRITE)',char(10),'GO',char(10))
from sys.databases
where is_query_store_on = 0
and database_id > 4