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

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

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

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

d = A("d")
i = B("i")
a = C("a")
f = D("f")
g = A("g")
l = B("l")
e = B("e")

d.u = e
d.q = a
d.w = a
i.r = f
a.o = d
a.w = f
f.q = g
g.u = l
g.q = a
g.w = a
l.r = f
e.r = f
assert l.r.q.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.q: C = None
        self.w: C = None
        self.txt = txt

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

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

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

d = A("d")
i = B("i")
a = C("a")
f = D("f")
g = A("g")
l = B("l")
e = B("e")

d.u = e
d.q = a
d.w = a
i.r = f
a.o = d
a.w = f
f.q = g
g.u = l
g.q = a
g.w = a
l.r = f
e.r = f
assert l.r.q.w.o.txt == "d"