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

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

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

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

d = A("d")
m = B("m")
c = C("c")
k = D("k")
a = D("a")
j = A("j")

d.q = m
m.w = k
c.o = j
c.u = m
c.x = m
c.v = m
k.x = a
a.x = k
j.q = m
assert m.w.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

d = A("d")
m = B("m")
c = C("c")
k = D("k")
a = D("a")
j = A("j")

d.q = m
m.w = k
c.o = j
c.u = m
c.x = m
c.v = m
k.x = a
a.x = k
j.q = m
assert m.w.x.x.x.x.x.txt == "a"