I want to create the functionality from below image

In this image there are buttons ‘A’,’A’,’C’,’E’ etc.
Now on click of this button I want the text of that button in the first blank box and then after clicking another button i want the text of that button on the 2nd blank box.
How can I implement this kind of functionality.
Any Idea?
let those buttons ‘A’,’A’,’C’,’E’ etc shares a common action method like