Convinced that happy cows give more milk, Farmer John has installed a giant disco ball in his barn and plans to teach his cows to dance.
After looking up popular cow dances, Farmer John settled on the Bovine Shuffle. In the Bovine Shuffle his N cows (1≤N≤100) line up in a row in some order and then perform three shuffles in a row, after which they stand in a possibly different order. To make it easier for the cows to locate themselves, Farmer John numbered the spots in the line 1 through N, so the first cow in the lineup stands at position 1, the next at position 2, and the last at position N.
One shuffle is described by N numbers a1,…,aN. During the shuffle the cow at position i moves to position ai, and every ai is between 1 and N. Every cow moves to its assigned position during the shuffle. All of the ai are distinct, so no two cows ever try to move to the same position.
Each of Farmer John's cows carries a 7-digit integer ID, and no two cows share an ID. Given the order of the cows after the three shuffles, determine the order they started in.