class A:
    def __init__(self, txt: str):
        self.x: 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.z: B = None
        self.p: B = None
        self.txt = txt

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

h = A("h")
j = B("j")
k = C("k")
m = D("m")

h.x = k
h.y = m
j.w = m
k.z = j
k.p = j
m.o = k
m.w = h
assert m.o.z.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: 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.z: B = None
        self.p: B = None
        self.txt = txt

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

h = A("h")
j = B("j")
k = C("k")
m = D("m")

h.x = k
h.y = m
j.w = m
k.z = j
k.p = j
m.o = k
m.w = h
assert m.o.z.w.w.txt == "h"