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

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

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

d = A("d")
b = B("b")
m = C("m")

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

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

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

d = A("d")
b = B("b")
m = C("m")

d.r = m
b.p = m
m.x = d
m.o = d
assert d.r.o.r.txt == "m"