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

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

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

m = A("m")
k = B("k")
n = C("n")
j = C("j")
g = A("g")
f = A("f")
e = C("e")
h = B("h")

m.z = g
k.y = j
k.x = n
n.x = m
j.x = m
g.z = m
f.z = m
e.x = m
h.y = n
h.x = n
assert k.y.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

m = A("m")
k = B("k")
n = C("n")
j = C("j")
g = A("g")
f = A("f")
e = C("e")
h = B("h")

m.z = g
k.y = j
k.x = n
n.x = m
j.x = m
g.z = m
f.z = m
e.x = m
h.y = n
h.x = n
assert k.y.x.z.txt == "g"