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

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

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

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

b = A("b")
g = B("g")
f = C("f")
c = D("c")
a = C("a")
m = A("m")
i = D("i")

b.z = c
g.p = i
g.y = c
g.w = f
f.w = m
f.r = g
c.p = i
a.w = b
a.r = g
m.z = c
i.p = c
assert b.z.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.txt = txt

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

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

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

b = A("b")
g = B("g")
f = C("f")
c = D("c")
a = C("a")
m = A("m")
i = D("i")

b.z = c
g.p = i
g.y = c
g.w = f
f.w = m
f.r = g
c.p = i
a.w = b
a.r = g
m.z = c
i.p = c
assert b.z.p.p.p.txt == "i"