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

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

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

h = A("h")
j = B("j")
m = C("m")
i = B("i")
a = C("a")

h.o = m
h.y = a
h.x = a
j.z = h
j.y = i
m.t = i
m.r = i
i.z = h
i.y = j
a.t = i
a.r = i
assert a.r.z.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.y: C = None
        self.x: C = None
        self.txt = txt

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

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

h = A("h")
j = B("j")
m = C("m")
i = B("i")
a = C("a")

h.o = m
h.y = a
h.x = a
j.z = h
j.y = i
m.t = i
m.r = i
i.z = h
i.y = j
a.t = i
a.r = i
assert a.r.z.o.r.txt == "i"