Enigma 1332: Square pins

George, and his brothers Fred and Henry, are comparing the PIN codes they have been given for their new credit cards. Each is a four digit number, and none contain a zero digit. The last digit of Fred’s number is the same as the first digit of George’s, the last digit of George’s is the first digit of Henry’s, and the last digit of Henry’s is the first digit of Fred’s. Apart from these three pairs of different digits, no digit occurs more than once among the PINs.

The brothers have each calculated the sum of the squares of the four digits in their PIN and to their great surprise they found that the three totals are exactly the same.

The question gives us no way to distinguish George, Fred and Henry, so for any solution (A, B, C) any other permutation will also be a solution. Hence the six solutions my program finds. Fortunately the sums of the digits for all three PINs is the same, so there is only one possible answer to the problem.