3. In one class, Ivan, Petr, and Sergey study. Their last names are Petrov, Ivanov, and Sergeev. Determine the last name of each boy, given that Ivan is not Ivanov, Petr is not Petrov, Sergey is not Sergeev, and that Sergey lives in the same house as Petrov. How did you reason?
3. This task involves the names of three boys (Ivan, Petr, Sergei) and their surnames (Ivanov, Petrov, Sergeev). Let's draw a table.

|  | I | $\Pi$ | S |
| :---: | :---: | :---: | :---: |
| $I$ |  |  |  |
| $\Pi$ |  |  |  |
| $S$ |  |  |  |

Capital letters on the left denote the boys' names, and capital letters at the top denote the boys' surnames. According to the problem, "Ivan is not Ivanov," "Petr is not Petrov," "Sergei is not Sergeev." Let's mark this in the table.

|  | I | $\Pi$ | S |
| :---: | :---: | :---: | :---: |
| I | - |  |  |
| $\Pi$ |  | - |  |
| S |  |  | - |

The last condition of the problem states that "Sergei lives in the same house as Petrov." Therefore, Sergei is not Petrov.

|  | I | $\Pi$ | S |
| :---: | :---: | :---: | :---: |
| I | - |  |  |
| $\Pi$ |  | - |  |
| S |  | - | - |

Then, according to the table, Sergei can only be Ivanov.

|  | I | $\Pi$ | S |
| :---: | :---: | :---: | :---: |
| I | - |  |  |
| $\Pi$ |  | - |  |
| S | + | - | - |

This means that no one else among the boys can have the surname Ivanov.

|  | I | $\Pi$ | S |
| :---: | :---: | :---: | :---: |
| I | - |  |  |
| $\Pi$ | - | - |  |
| S | + | - | - |

According to the table, Petr can only have the surname Sergeev.

|  | I | $\Pi$ | S |
| :---: | :---: | :---: | :---: |
| I | - |  |  |
| $\Pi$ | - | - | + |
| S | + | - | - |

Then Ivan's surname is Petrov.

|  | I | $\Pi$ | S |
| :---: | :---: | :---: | :---: |
| I | - | + | - |
| $\Pi$ | - | - | + |
| S | + | - | - |

Answer: Ivan Petrov, Petr Sergeev, Sergei Ivanov.