I'm presuming that you started one way and want to change the process and data storage a different way. In other words, this merge process is a one time thing.
One way to do this is to create a new table and run a couple of imports. The import should "Update matching records in found set" and match on the UID field. You'll need to run the import a couple of times. The first time, find all the position = head and export the results. Import matching the UID field as mentioned above and B ---> B_head and P ---> P_head.
Repeat the process for tails: find position = tails, export, import matching UID and B ---> B_tail, P---> P_tail.
define 2 dummy fields, calculated. posHead = "head" and posTail = "tail".
create 2 relationships based upon 2 criteria:
UID = UID and posHead = Position
UID = UID and posTail = Position
define the 4 fields you mention as autoenter lookup via these 2 relations.
Select all records, relookup on UID, you're done.
To prevent bad news, if it's a one-time only job, take away the lookup once done (delete the 2 dummies and the relationships, too)
It works，thank you very much。