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

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

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

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

l = A("l")
h = B("h")
d = C("d")
c = D("c")
a = B("a")
k = D("k")
f = B("f")

l.r = d
h.p = a
d.t = k
c.r = k
a.p = h
k.r = c
f.p = h
assert c.r.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

l = A("l")
h = B("h")
d = C("d")
c = D("c")
a = B("a")
k = D("k")
f = B("f")

l.r = d
h.p = a
d.t = k
c.r = k
a.p = h
k.r = c
f.p = h
assert c.r.r.r.r.r.r.r.txt == "k"