Keilim, Chapter 18, Mishnah 8. This mishnah takes up a case involving tefillin: a shel rosh that contracted tum'ah, and whose compartments were then removed one at a time and replaced with pure ones. Step by step the Mishnah follows the tum'ah as it weakens and finally disappears altogether.
How tefillin are built
Tefillin contain four parashiyot. In the shel yad, worn on the arm, the four sections are all inscribed on one continuous piece of klaf; that single piece is wound into a scroll and inserted into a single bayit. The shel rosh works differently: there each of the four parashiyot has its own separate klaf, every one wound up by itself and set into a bayit of its own, giving the head tefillin four little boxes standing in a row. Our mishnah deals with the shel rosh.
Four compartments, four keilim
The Mishnah begins: "Tefillah arba'ah keilim", a tefillah (of the head) constitutes four keilim. When it comes to tum'ah, every one of the four batim carries the status of a keli by itself, and they are not treated as a single utensil made up of parts. Everything the Mishnah goes on to say rests on this.
The case: tum'at meis
The tefillin came into contact with a corpse and became tamei with tum'at meis, which places them at the level of an av hatum'ah. Now the owner sets about repairing them, compartment by compartment.
"Hitir ketzitzah harishonah v'tiknah, temei'ah tamei meis": he untied the first of the batim and restored the tefillin by fitting a tahor bayit in its place. The substitute does not remain tahor for long. Since it is bound together with the other three batim, which still bear tum'at meis on the level of an av, it too acquires tum'at meis.
"V'chein hasheniyah, v'chein hashelishit": exactly the same happens with the second and the third. Each time a compartment is removed and a pure one takes its place, the newcomer becomes tamei with tum'at meis, because it is attached to the compartment or compartments that still remain from the original tefillin and are tamei on that level.
Removing the fourth
"Hitir et harevi'it, tehorah mitamei meis": when he finally removes the fourth original compartment as well and installs a pure one, the tefillin are no longer tamei with tum'at meis. The new fourth compartment is clean of it, since there is nothing left in the tefillin at the level of an av hatum'ah, and the first three replacements also shed their tum'at meis, because they are no longer attached to anything that carries that level of tum'ah.
"Aval temei'ah maga tamei meis": they are not, however, entirely tahor. Every one of the three substitutes had been put in while the original fourth bayit, an av hatum'ah, was still in place, and each of them was in contact with it. A keli that touches an av hatum'ah is left tamei on the level of a rishon, and so those three retain rishon-level tum'ah from that contact. The fourth substitute is a rishon too, being joined to the three that are rishon.
Starting the round again
"Chazar larishonah v'hitirah v'tiknah, temei'ah b'maga": he now returns to the bayit he had put in first, unties it, and fixes the tefillin with another tahor one. This latest bayit acquires rishon-level tum'ah through contact, since it is bound to the two middle batim, which hold the status of rishon.
"V'chein lasheniyah": the same when he removes the second and puts in a pure one; the new second compartment becomes a rishon by contact, because it is attached to the third, which is still a rishon.
The last step, and the whole tefillin is tahor
"Hitir et hashelishit, tehorah": he now removes the third of that round and installs a pure compartment, and at this point the entire tefillin is tahor. The Mishnah gives the reason: "shehareviit b'maga v'ein maga oseh maga", the fourth compartment is tamei only through contact, and something tamei through contact does not pass tum'ah on by contact.
Recall how the fourth compartment picked up its tum'ah in the first place. It was a rishon only because it was joined to the other three, which had themselves become rishon by touching the original fourth compartment that carried tum'at meis. But a keli that is a rishon does not render another keli tamei. So the fourth compartment had no independent standing at all; it was, so to speak, being dragged along after its neighbors, nigrar acharehen, tamei only for as long as it was attached to keilim that were genuinely rishon.
Once those three have been removed and replaced with pure compartments, the fourth has nothing left to lean on. Its own tum'ah falls away, and it cannot transmit anything to the new compartments beside it, since maga does not produce maga. The result is that the tefillin, all four compartments together, are completely tahor.