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

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

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

l = A("l")
i = B("i")
g = C("g")
f = A("f")
a = A("a")

l.x = i
i.z = g
g.w = i
g.z = f
f.x = i
a.x = i
assert a.x.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

l = A("l")
i = B("i")
g = C("g")
f = A("f")
a = A("a")

l.x = i
i.z = g
g.w = i
g.z = f
f.x = i
a.x = i
assert a.x.z.z.txt == "f"