Issue with foreach loop

This is part of an item inventory. I’m having trouble with a foreach loop. The idea is, I want to group like-items so I can later count them easily. Problem is, anytime I give it a struct containing items A, A, B; B remains and the loop exits. It doesn’t seem to set EACH to temp. Not sure what is happening.

Another example of what I want loops like this:

given a struct containing items A,A,B,A,C. The script will produce the output A, A, A, B, C.

Here’s the blueprint.