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

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

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

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

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

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

b.o = d
b.r = d
c.s = b
d.o = b
d.r = b
assert c.s.r.o.txt == "b"