gh-36553: Add a hash function for the class TernaryQF.
PR from #16956 (rebased from https://github.com/sagemath/sagetrac-
mirror/commit/091cbbdf6eed2c8bccca407addd07ff08e429c17)
Author: Gustavo Rama
### :memo: Checklist
- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.
URL: https://github.com/sagemath/sage/pull/36553
Reported by: Gonzalo TornarĂa
Reviewer(s):