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

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

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

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

d = A("d")
h = B("h")
f = C("f")
i = D("i")
e = B("e")
l = D("l")

d.p = l
d.x = f
h.p = i
h.s = e
f.r = l
f.x = d
i.p = f
i.y = l
i.s = h
e.p = l
e.s = h
l.p = f
l.y = i
l.s = e
assert f.x.x.x.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.x: C = None
        self.txt = txt

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

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

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

d = A("d")
h = B("h")
f = C("f")
i = D("i")
e = B("e")
l = D("l")

d.p = l
d.x = f
h.p = i
h.s = e
f.r = l
f.x = d
i.p = f
i.y = l
i.s = h
e.p = l
e.s = h
l.p = f
l.y = i
l.s = e
assert f.x.x.x.p.y.txt == "i"