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

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

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

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

j = A("j")
n = B("n")
e = C("e")
h = D("h")
m = C("m")
d = D("d")
c = B("c")
g = A("g")
f = A("f")
l = B("l")

j.r = f
n.r = m
e.o = d
h.v = g
h.p = d
m.o = d
d.v = g
d.p = h
c.r = e
g.r = j
f.r = j
l.r = e
assert j.r.r.r.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

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

j = A("j")
n = B("n")
e = C("e")
h = D("h")
m = C("m")
d = D("d")
c = B("c")
g = A("g")
f = A("f")
l = B("l")

j.r = f
n.r = m
e.o = d
h.v = g
h.p = d
m.o = d
d.v = g
d.p = h
c.r = e
g.r = j
f.r = j
l.r = e
assert j.r.r.r.r.r.r.r.r.r.txt == "f"