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

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

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

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

m = A("m")
a = B("a")
n = C("n")
f = D("f")
l = B("l")
h = C("h")
e = D("e")
i = A("i")
b = C("b")

m.x = i
m.s = f
m.u = f
a.w = i
a.u = n
n.y = b
f.u = h
l.w = m
l.u = n
h.y = n
e.u = n
i.x = m
i.s = e
i.u = f
b.y = h
assert m.x.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.s: D = None
        self.u: D = None
        self.txt = txt

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

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

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

m = A("m")
a = B("a")
n = C("n")
f = D("f")
l = B("l")
h = C("h")
e = D("e")
i = A("i")
b = C("b")

m.x = i
m.s = f
m.u = f
a.w = i
a.u = n
n.y = b
f.u = h
l.w = m
l.u = n
h.y = n
e.u = n
i.x = m
i.s = e
i.u = f
b.y = h
assert m.x.x.s.txt == "f"