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

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

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

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

a = A("a")
f = B("f")
n = C("n")
c = D("c")
e = D("e")
d = B("d")

a.r = n
f.z = a
f.u = e
f.w = n
n.x = e
c.r = n
c.y = d
e.r = n
e.y = d
d.z = a
d.u = c
d.w = n
assert a.r.x.y.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

a = A("a")
f = B("f")
n = C("n")
c = D("c")
e = D("e")
d = B("d")

a.r = n
f.z = a
f.u = e
f.w = n
n.x = e
c.r = n
c.y = d
e.r = n
e.y = d
d.z = a
d.u = c
d.w = n
assert a.r.x.y.w.x.txt == "e"