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

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

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

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

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

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

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

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

d.o = g
g.r = d
b.t = d
b.p = g
assert d.o.r.o.txt == "g"