5. In the game "set," all possible four-digit numbers consisting of the digits $1,2,3$ (each digit appearing exactly once) are used. It is said that a triplet of numbers forms a set if, in each digit place, either all three numbers contain the same digit, or all three numbers contain different digits.

For example, the numbers 1232, 2213, 3221 form a set (in the first place, all three digits appear, in the second place, only the digit two appears, in the third place, all three digits appear, and in the fourth place, all three digits appear). The numbers $1123,2231,3311$ do not form a set (in the last place, two ones and a three appear).

How many sets exist in the game?

(Permuting the numbers does not create a new set: $1232,2213,3221$ and $2213,1232,3221$ are the same set.)
Solution. Note that for any two numbers, there exists exactly one set in which they occur. Indeed, the third number of this set is constructed as follows: in the positions where the first two numbers coincide, the third number has the same digit; in the position where the first two numbers differ, the third number gets the remaining digit. For example, for the numbers 1231 and 1223, the third in the set will be 1212.

Let's call an "ordered set" a set of three four-digit numbers with their order taken into account. In such a sequence, the first place can be occupied by any of the 81 numbers, the second by any of the 80 remaining; the third is exactly one (according to the principle described above). In total, there are $81 \cdot 80 \cdot 1$ ordered sets. Note that each unordered set $\{a, b, c\}$ corresponds to six ordered sets: $(a, b, c),(a, c, b),(b, a, c),(b, c, a),(c, a, b),(c, b, a)$. Therefore, there are six times fewer ordered sets.

Answer: $81 \cdot 80 / 6=1080$.