6. (40 points) In each small square of a $9 \times 9$ grid, fill in a number such that each row and each column contains at most four different numbers. What is the maximum number of different numbers that can be in this grid?


6. Suppose this square table contains 29 different numbers. According to the pigeonhole principle, there must be a row with four different numbers, let's assume it is the first row. The remaining 25 numbers are in rows $2 \sim 9$. Similarly, according to the pigeonhole principle, there must be a row with four, let's assume it is the second row.

Next, observe the numbers in each column of the square table. Each column already has two different numbers at the top, so each column below the second row can have at most two different numbers. This way, the maximum number of different numbers is $8+9 \times 2=26$, which is a contradiction. Therefore, the number of different numbers is less than 29.

Figure 13 constructs a $9 \times 9$ square table containing 28 different numbers, with each row and each column having exactly four different numbers. Another filling method is shown in Figure 14.