class A:
    def __init__(self, txt: str):
        self.r: C = 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.x: B = None
        self.txt = txt

n = A("n")
g = B("g")
h = C("h")
f = B("f")

n.r = h
g.r = n
h.x = f
f.r = n
assert g.r.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = 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.x: B = None
        self.txt = txt

n = A("n")
g = B("g")
h = C("h")
f = B("f")

n.r = h
g.r = n
h.x = f
f.r = n
assert g.r.r.x.txt == "f"