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

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

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

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

f = A("f")
b = B("b")
c = C("c")
l = D("l")
h = C("h")

f.u = b
b.z = l
c.t = l
c.v = l
l.p = h
l.v = f
h.t = l
h.v = l
assert f.u.z.v.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

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

f = A("f")
b = B("b")
c = C("c")
l = D("l")
h = C("h")

f.u = b
b.z = l
c.t = l
c.v = l
l.p = h
l.v = f
h.t = l
h.v = l
assert f.u.z.v.u.txt == "b"