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

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

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

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

a = A("a")
j = B("j")
m = C("m")
h = D("h")
f = D("f")
l = D("l")
i = A("i")

a.y = i
a.p = i
a.x = j
a.r = l
j.p = m
j.u = a
m.t = j
h.t = a
h.s = m
f.t = i
f.s = m
l.t = i
l.s = m
i.y = a
i.p = a
i.x = j
i.r = l
assert m.t.u.y.y.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.p: A = None
        self.x: B = None
        self.r: D = None
        self.txt = txt

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

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

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

a = A("a")
j = B("j")
m = C("m")
h = D("h")
f = D("f")
l = D("l")
i = A("i")

a.y = i
a.p = i
a.x = j
a.r = l
j.p = m
j.u = a
m.t = j
h.t = a
h.s = m
f.t = i
f.s = m
l.t = i
l.s = m
i.y = a
i.p = a
i.x = j
i.r = l
assert m.t.u.y.y.y.r.txt == "l"