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

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

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

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

f = A("f")
i = B("i")
g = C("g")
d = D("d")

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

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

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

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

f = A("f")
i = B("i")
g = C("g")
d = D("d")

f.s = d
i.p = g
g.z = d
g.t = d
g.s = f
d.w = g
assert g.s.s.w.txt == "g"