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

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

e = A("e")
f = B("f")
m = A("m")
i = B("i")

e.z = m
e.x = f
f.x = m
f.r = i
m.z = e
m.x = f
i.x = m
i.r = f
assert i.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.x: B = None
        self.txt = txt

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

e = A("e")
f = B("f")
m = A("m")
i = B("i")

e.z = m
e.x = f
f.x = m
f.r = i
m.z = e
m.x = f
i.x = m
i.r = f
assert i.x.x.x.txt == "m"