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

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

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

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

n = A("n")
f = B("f")
i = C("i")
b = D("b")
h = D("h")
e = C("e")

n.p = f
f.y = n
i.y = h
i.w = h
i.p = h
b.x = f
b.u = i
h.x = f
h.u = i
e.y = b
e.w = h
e.p = h
assert n.p.y.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

n = A("n")
f = B("f")
i = C("i")
b = D("b")
h = D("h")
e = C("e")

n.p = f
f.y = n
i.y = h
i.w = h
i.p = h
b.x = f
b.u = i
h.x = f
h.u = i
e.y = b
e.w = h
e.p = h
assert n.p.y.p.y.txt == "n"