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

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

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

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

h = A("h")
l = B("l")
b = C("b")
a = D("a")
n = D("n")
g = B("g")
e = D("e")
f = C("f")
m = B("m")

h.y = l
l.r = a
b.r = h
a.r = l
n.r = l
g.r = e
e.r = g
f.r = h
m.r = a
assert a.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

h = A("h")
l = B("l")
b = C("b")
a = D("a")
n = D("n")
g = B("g")
e = D("e")
f = C("f")
m = B("m")

h.y = l
l.r = a
b.r = h
a.r = l
n.r = l
g.r = e
e.r = g
f.r = h
m.r = a
assert a.r.r.r.txt == "l"