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

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

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

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

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

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

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