Sort File Into "Variable Subfolder" Based on a Tag

I have been looking around but cannot find a solution that works for my case. There are many similar cases, but none that works for mine.


I have clients A, B, C, D, and E (overall more than 5000).

Each client has a specific client number (A = 0001, B = 0002, etc).
Each matter has a unique matter number combined of the client number and the matter number, e.g. matter 1 for client A has the number "00010001". The second matter of client A has the number "00010002". To show the logic: the third matter of client E has hence the unique matter number "00050003" (client E & matter 3).

Each new file I download in my "Inbox" or "Scan Folder" gets as a tag the specific unique matter number (e.g. 00050003).

My (main) folder structure is the following:

~/Clients/0001 (ABC)
~/Clients/0002 (YXZ)

with each having subfolders like:

~/Clients/0001 (ABC)/00010001 (...)
~/Clients/0002 (YXZ)/00020001 (...)
                    /00020003 (...)

Now I am looking for a way that KM, Automator or Hazel reads the specific tag (that has basically two variables) and moves the file, eg with the Tag "00020003" (= Client B, matter 3) to this specific folder.

Here in the KM Forum I have found a way to sort things into the Main folder of the client.

Now I am looking for a solution to move it directly to the subfolder, because otherwise I need to set this up for each client. With a list of more than 5000 clients, this is too much.

Anyone has a solution running for this, or knows how to set it up?

Many thanks in advance.