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

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

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

n = A("n")
i = B("i")
f = C("f")

n.x = f
i.x = n
f.r = i
f.w = i
assert f.r.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

n = A("n")
i = B("i")
f = C("f")

n.x = f
i.x = n
f.r = i
f.w = i
assert f.r.x.x.txt == "f"