This may need some alterations depending on your Excel version, and how your inputs/outputs are formatted.
For the first column:
=TOCOL(HSTACK(Table1[ID],Table1[ID],Table1[ID]))
For the second:
="PQ"&MOD(SEQUENCE(ROWS(B9#),,3),3)+1
, where B9 for me refers to the first cell of the new ID column.
For the third column:
=IFS(C9#="PQ1", XLOOKUP(B9#, Table1[ID], Table1[P1]), C9#="PQ2", XLOOKUP(B9#, Table1[ID], Table1[P2]), C9#="PQ3", XLOOKUP(B9#, Table1[ID], Table1[P3]))
, where C9 refers to the first cell of the "A" column.
Similarly, for the last column:
=IFS(C9#="PQ1", XLOOKUP(B9#, Table1[ID], Table1[Q1]), C9#="PQ2", XLOOKUP(B9#, Table1[ID], Table1[Q2]), C9#="PQ3", XLOOKUP(B9#, Table1[ID], Table1[Q3]))
As I said, this might need some alterations, but let me know if so.