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

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

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

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

f = A("f")
m = B("m")
e = C("e")
a = D("a")
h = C("h")

f.t = h
m.p = h
e.y = a
e.v = m
a.t = m
a.s = m
h.y = a
h.v = m
assert h.v.p.y.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

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

f = A("f")
m = B("m")
e = C("e")
a = D("a")
h = C("h")

f.t = h
m.p = h
e.y = a
e.v = m
a.t = m
a.s = m
h.y = a
h.v = m
assert h.v.p.y.t.p.txt == "h"