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

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

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

d = A("d")
i = B("i")
h = C("h")
j = B("j")
n = A("n")
e = C("e")
c = C("c")
f = C("f")

d.p = n
i.s = d
i.y = e
i.r = h
h.z = i
j.s = d
j.y = f
j.r = h
n.p = d
e.z = i
c.z = i
f.z = i
assert i.s.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

d = A("d")
i = B("i")
h = C("h")
j = B("j")
n = A("n")
e = C("e")
c = C("c")
f = C("f")

d.p = n
i.s = d
i.y = e
i.r = h
h.z = i
j.s = d
j.y = f
j.r = h
n.p = d
e.z = i
c.z = i
f.z = i
assert i.s.p.p.p.txt == "n"