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

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

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

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

g = A("g")
l = B("l")
m = C("m")
j = D("j")
i = B("i")

g.z = i
l.w = g
l.y = i
m.p = g
m.w = i
m.x = l
j.p = l
i.w = g
i.y = l
assert j.p.w.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

g = A("g")
l = B("l")
m = C("m")
j = D("j")
i = B("i")

g.z = i
l.w = g
l.y = i
m.p = g
m.w = i
m.x = l
j.p = l
i.w = g
i.y = l
assert j.p.w.z.y.txt == "l"