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

l = A("l")
d = B("d")
g = B("g")
h = B("h")

l.x = d
d.y = g
g.y = d
h.y = g
assert h.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

l = A("l")
d = B("d")
g = B("g")
h = B("h")

l.x = d
d.y = g
g.y = d
h.y = g
assert h.y.y.y.txt == "g"