A query is processed by a single node and not forwarded to the rest of the network (like a transaction) for processing into consensus state. To compensate that particular node for the costs of processing a query, the query contains an embedded payment transaction. The node processing the query submits that embedded payment transaction to the network in order to receive its node fee.
Note that the client will pay the full amount that they stipulate for this payment transaction - there is no protection against overpayment as for transactions. Before sending a a query with a payment transaction, clients can first ask a node for the approriate value of this payment - and so guard against overpayment.