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

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

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

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

c = A("c")
h = B("h")
l = C("l")
m = D("m")
k = C("k")

c.y = k
h.y = k
h.v = c
h.z = c
h.o = m
l.w = k
m.v = h
k.w = l
assert k.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

c = A("c")
h = B("h")
l = C("l")
m = D("m")
k = C("k")

c.y = k
h.y = k
h.v = c
h.z = c
h.o = m
l.w = k
m.v = h
k.w = l
assert k.w.w.w.txt == "l"