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

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

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

h.y = b
m.x = h
f.x = b
b.y = h
assert f.x.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

h.y = b
m.x = h
f.x = b
b.y = h
assert f.x.y.y.txt == "b"