class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.z: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

m = A("m")
e = B("e")
k = B("k")
h = A("h")

m.t = k
m.z = k
e.z = k
k.z = e
h.t = k
h.z = e
assert m.t.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.z: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

m = A("m")
e = B("e")
k = B("k")
h = A("h")

m.t = k
m.z = k
e.z = k
k.z = e
h.t = k
h.z = e
assert m.t.z.z.z.txt == "e"