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

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

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

n = A("n")
m = B("m")
l = C("l")
h = A("h")
f = B("f")
d = C("d")

n.z = h
m.z = h
m.y = d
l.t = d
l.w = h
l.r = h
h.z = n
f.z = n
f.y = l
d.t = l
d.w = h
d.r = h
assert d.r.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

n = A("n")
m = B("m")
l = C("l")
h = A("h")
f = B("f")
d = C("d")

n.z = h
m.z = h
m.y = d
l.t = d
l.w = h
l.r = h
h.z = n
f.z = n
f.y = l
d.t = l
d.w = h
d.r = h
assert d.r.z.z.z.z.txt == "h"