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

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

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

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

i = A("i")
h = B("h")
g = C("g")
l = D("l")

i.w = h
i.p = l
h.z = i
h.s = i
h.r = l
g.t = l
g.w = l
l.z = g
assert g.t.z.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.p: D = None
        self.txt = txt

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

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

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

i = A("i")
h = B("h")
g = C("g")
l = D("l")

i.w = h
i.p = l
h.z = i
h.s = i
h.r = l
g.t = l
g.w = l
l.z = g
assert g.t.z.t.z.txt == "g"