I don't think it makes sense to see foo here, since foo was never
used as replacement text.
It seems what you want is a separate history for each of from/to prompts.
You can do this by the following settings:
(defvar query-replace-from-history nil)
(defvar query-replace-to-history nil)
(setq
Please write in English if possible, because the Emacs maintainers
usually do not have translators to read other languages for them.
Your bug report will be posted to the emacs-pretest-bug@gnu.org mailing list.
Please describe exactly what actions triggered the bug
and the precise symptoms of