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

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

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

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

m = A("m")
a = B("a")
g = C("g")
c = D("c")

m.u = g
m.y = c
a.w = c
g.o = c
c.w = a
c.u = a
c.x = m
assert g.o.w.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.y: D = None
        self.txt = txt

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

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

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

m = A("m")
a = B("a")
g = C("g")
c = D("c")

m.u = g
m.y = c
a.w = c
g.o = c
c.w = a
c.u = a
c.x = m
assert g.o.w.w.x.txt == "m"