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

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

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

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

b.r = f
f.r = c
g.x = b
d.r = g
c.x = b
assert c.x.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

b.r = f
f.r = c
g.x = b
d.r = g
c.x = b
assert c.x.r.r.txt == "c"