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

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

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

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

j = A("j")
d = B("d")
c = C("c")
h = D("h")
i = C("i")

j.p = h
j.z = c
j.w = c
d.p = j
d.z = h
c.r = j
c.y = j
h.y = i
i.r = j
i.y = j
assert j.p.y.y.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.z: C = None
        self.w: C = None
        self.txt = txt

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

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

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

j = A("j")
d = B("d")
c = C("c")
h = D("h")
i = C("i")

j.p = h
j.z = c
j.w = c
d.p = j
d.z = h
c.r = j
c.y = j
h.y = i
i.r = j
i.y = j
assert j.p.y.y.p.y.txt == "i"