class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

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

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

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

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

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

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

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

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