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

i = A("i")
a = B("a")
d = B("d")

i.p = a
a.x = d
d.x = a
assert i.p.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

i = A("i")
a = B("a")
d = B("d")

i.p = a
a.x = d
d.x = a
assert i.p.x.x.txt == "a"