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

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

i = A("i")
n = B("n")
m = A("m")
d = B("d")

i.z = m
n.x = m
m.z = i
d.x = m
assert m.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

i = A("i")
n = B("n")
m = A("m")
d = B("d")

i.z = m
n.x = m
m.z = i
d.x = m
assert m.z.z.z.txt == "i"