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

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

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

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

m = A("m")
c = B("c")
l = C("l")
e = D("e")
b = A("b")
a = C("a")
h = D("h")
j = D("j")
f = C("f")

m.r = j
c.t = b
c.v = b
c.s = m
c.p = f
l.y = h
l.w = j
e.p = f
e.r = m
b.r = h
a.y = h
a.w = j
h.p = l
h.r = b
j.p = f
j.r = b
f.y = e
f.w = e
assert m.r.r.r.r.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

m = A("m")
c = B("c")
l = C("l")
e = D("e")
b = A("b")
a = C("a")
h = D("h")
j = D("j")
f = C("f")

m.r = j
c.t = b
c.v = b
c.s = m
c.p = f
l.y = h
l.w = j
e.p = f
e.r = m
b.r = h
a.y = h
a.w = j
h.p = l
h.r = b
j.p = f
j.r = b
f.y = e
f.w = e
assert m.r.r.r.r.r.p.txt == "l"