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

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

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

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

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

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

f.x = h
f.s = e
e.z = f
m.x = e
m.s = e
h.z = f
assert e.z.x.z.txt == "f"