class A:
    def __init__(self, txt: str):
        self.t: D = 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.z: B = None
        self.r: B = None
        self.p: D = None
        self.txt = txt

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

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

g.t = h
l.z = h
b.z = f
b.r = f
b.p = h
h.t = f
f.z = h
assert b.r.z.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = 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.z: B = None
        self.r: B = None
        self.p: D = None
        self.txt = txt

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

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

g.t = h
l.z = h
b.z = f
b.r = f
b.p = h
h.t = f
f.z = h
assert b.r.z.t.txt == "f"