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

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

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

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

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

b.q = m
d.q = i
d.t = e
d.w = a
d.s = a
e.r = d
l.p = a
a.p = l
i.q = d
i.t = e
i.w = a
i.s = a
m.q = b
assert m.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

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

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

b.q = m
d.q = i
d.t = e
d.w = a
d.s = a
e.r = d
l.p = a
a.p = l
i.q = d
i.t = e
i.w = a
i.s = a
m.q = b
assert m.q.q.q.q.q.q.txt == "m"