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

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

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

class D:
    def __init__(self, txt: str):
        self.v: B = None
        self.p: B = None
        self.txt = txt

d = A("d")
n = B("n")
j = C("j")
a = D("a")
e = B("e")
g = D("g")

d.y = a
d.z = a
n.p = j
n.u = a
j.y = n
a.v = n
a.p = e
e.p = j
e.u = g
g.v = e
g.p = n
assert j.y.u.v.u.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.z: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.v: B = None
        self.p: B = None
        self.txt = txt

d = A("d")
n = B("n")
j = C("j")
a = D("a")
e = B("e")
g = D("g")

d.y = a
d.z = a
n.p = j
n.u = a
j.y = n
a.v = n
a.p = e
e.p = j
e.u = g
g.v = e
g.p = n
assert j.y.u.v.u.p.u.txt == "g"