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

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

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

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

g = A("g")
f = B("f")
d = C("d")
e = D("e")
j = B("j")
i = B("i")
n = D("n")
c = C("c")
b = B("b")

g.o = e
g.x = c
f.y = g
d.z = c
d.q = g
e.y = n
e.w = g
e.z = g
j.y = g
i.y = g
n.y = e
n.w = g
n.z = g
c.z = d
c.q = g
b.y = g
assert e.y.z.o.w.o.w.o.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.x: C = None
        self.txt = txt

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

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

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

g = A("g")
f = B("f")
d = C("d")
e = D("e")
j = B("j")
i = B("i")
n = D("n")
c = C("c")
b = B("b")

g.o = e
g.x = c
f.y = g
d.z = c
d.q = g
e.y = n
e.w = g
e.z = g
j.y = g
i.y = g
n.y = e
n.w = g
n.z = g
c.z = d
c.q = g
b.y = g
assert e.y.z.o.w.o.w.o.y.y.txt == "e"