class A:
    def __init__(self, txt: str):
        self.y: C = 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.r: B = None
        self.y: A = None
        self.z: B = None
        self.txt = txt

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

a = A("a")
k = B("k")
m = C("m")
c = D("c")
n = D("n")
l = A("l")
h = D("h")

a.y = m
k.z = m
m.r = k
m.z = k
m.y = l
c.u = m
c.r = k
c.w = l
n.u = m
n.r = k
n.w = l
l.y = m
h.u = m
h.r = k
h.w = l
assert h.w.y.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = 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.r: B = None
        self.y: A = None
        self.z: B = None
        self.txt = txt

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

a = A("a")
k = B("k")
m = C("m")
c = D("c")
n = D("n")
l = A("l")
h = D("h")

a.y = m
k.z = m
m.r = k
m.z = k
m.y = l
c.u = m
c.r = k
c.w = l
n.u = m
n.r = k
n.w = l
l.y = m
h.u = m
h.r = k
h.w = l
assert h.w.y.z.z.txt == "m"