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

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

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

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

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

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

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

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

f.r = c
c.w = d
d.y = f
assert c.w.y.r.txt == "c"