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

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

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

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

j = A("j")
b = B("b")
f = C("f")
e = D("e")
g = B("g")

j.w = g
b.t = f
f.z = e
e.z = g
e.y = j
g.t = f
assert e.y.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

j = A("j")
b = B("b")
f = C("f")
e = D("e")
g = B("g")

j.w = g
b.t = f
f.z = e
e.z = g
e.y = j
g.t = f
assert e.y.w.t.txt == "f"