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

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

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

h = A("h")
k = B("k")
d = C("d")
i = A("i")

h.z = d
h.y = d
k.v = i
k.r = d
k.z = h
d.x = k
d.s = h
i.z = d
i.y = d
assert h.y.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.y: C = None
        self.txt = txt

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

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

h = A("h")
k = B("k")
d = C("d")
i = A("i")

h.z = d
h.y = d
k.v = i
k.r = d
k.z = h
d.x = k
d.s = h
i.z = d
i.y = d
assert h.y.x.z.txt == "h"