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

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

class C:
    def __init__(self, txt: str):
        self.o: B = None
        self.v: A = None
        self.s: A = None
        self.txt = txt

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

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

d.y = m
d.x = b
m.u = b
m.p = d
a.o = e
a.v = d
a.s = d
b.o = d
b.z = n
b.w = f
n.o = e
n.v = d
n.s = d
f.o = d
f.z = n
f.w = b
e.u = f
e.p = d
assert b.z.o.u.w.z.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.x: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.o: B = None
        self.v: A = None
        self.s: A = None
        self.txt = txt

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

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

d.y = m
d.x = b
m.u = b
m.p = d
a.o = e
a.v = d
a.s = d
b.o = d
b.z = n
b.w = f
n.o = e
n.v = d
n.s = d
f.o = d
f.z = n
f.w = b
e.u = f
e.p = d
assert b.z.o.u.w.z.o.p.txt == "d"