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

class B:
    def __init__(self, txt: str):
        self.q: D = None
        self.p: D = None
        self.w: C = None
        self.y: C = None
        self.txt = txt

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

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

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

c.u = a
a.q = i
a.p = h
a.w = n
a.y = n
n.r = i
n.u = a
h.x = c
m.u = a
i.x = m
assert h.x.u.p.x.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: D = None
        self.p: D = None
        self.w: C = None
        self.y: C = None
        self.txt = txt

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

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

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

c.u = a
a.q = i
a.p = h
a.w = n
a.y = n
n.r = i
n.u = a
h.x = c
m.u = a
i.x = m
assert h.x.u.p.x.u.w.txt == "n"