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

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

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

n = A("n")
i = B("i")
g = C("g")
f = B("f")
k = A("k")
a = A("a")
j = C("j")

n.y = i
i.z = f
g.w = n
f.z = i
k.y = i
a.y = i
j.w = k
assert g.w.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

n = A("n")
i = B("i")
g = C("g")
f = B("f")
k = A("k")
a = A("a")
j = C("j")

n.y = i
i.z = f
g.w = n
f.z = i
k.y = i
a.y = i
j.w = k
assert g.w.y.z.txt == "f"