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

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

l = A("l")
e = B("e")
d = B("d")

l.p = e
e.x = d
d.x = e
assert e.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

l = A("l")
e = B("e")
d = B("d")

l.p = e
e.x = d
d.x = e
assert e.x.x.x.txt == "d"