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

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

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

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

a = A("a")
g = B("g")
i = C("i")
e = D("e")

a.z = g
g.q = i
g.p = i
i.q = e
i.w = e
e.w = g
e.q = i
e.p = i
e.s = a
assert g.p.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

a = A("a")
g = B("g")
i = C("i")
e = D("e")

a.z = g
g.q = i
g.p = i
i.q = e
i.w = e
e.w = g
e.q = i
e.p = i
e.s = a
assert g.p.w.s.txt == "a"