Personalization: reference to publications in several categories

I have posts assigned to several categories, as in this example:

Message 1> Cat A, Cat B
Position 2> Cat A, Cat B, Cat C
Message 3> Cat B, Cat C

Publications are accessed through category pages, and in the part of the content.php template of publications, I would like to show the name of the category page from which the publication was accessed, for example:

Publication 1> accessed from Cat A> publication shows & # 39; Cat A & # 39;
Publication 1> accessed from Cat B> publication shows & # 39; Cat B & # 39;

However, no matter what you have tried so far, the publications always show the name of the first category (lowest identification number).

Is there a way to make the publication template dynamically display the relevant reference page / category?