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

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

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

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

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

a.q = m
a.v = m
a.u = b
a.y = e
b.t = m
m.o = e
i.r = b
i.w = b
d.r = b
d.w = b
e.q = m
e.v = m
e.u = b
e.y = a
assert d.r.t.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.u: B = None
        self.y: A = None
        self.v: C = None
        self.txt = txt

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

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

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

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

a.q = m
a.v = m
a.u = b
a.y = e
b.t = m
m.o = e
i.r = b
i.w = b
d.r = b
d.w = b
e.q = m
e.v = m
e.u = b
e.y = a
assert d.r.t.o.txt == "e"