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

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

c = A("c")
b = B("b")
d = A("d")

c.o = d
b.p = d
d.o = c
assert c.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

c = A("c")
b = B("b")
d = A("d")

c.o = d
b.p = d
d.o = c
assert c.o.o.o.txt == "d"