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

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

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

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

a = A("a")
d = B("d")
h = C("h")
c = D("c")
i = B("i")
j = D("j")
e = C("e")
n = A("n")

a.u = j
d.x = a
d.y = e
h.x = i
h.p = j
h.y = d
h.q = e
c.z = a
c.p = j
i.x = n
i.y = e
j.z = n
j.p = c
e.x = d
e.y = d
e.p = c
e.q = h
n.u = c
assert e.p.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

a = A("a")
d = B("d")
h = C("h")
c = D("c")
i = B("i")
j = D("j")
e = C("e")
n = A("n")

a.u = j
d.x = a
d.y = e
h.x = i
h.p = j
h.y = d
h.q = e
c.z = a
c.p = j
i.x = n
i.y = e
j.z = n
j.p = c
e.x = d
e.y = d
e.p = c
e.q = h
n.u = c
assert e.p.z.u.txt == "j"