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

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

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

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

j = A("j")
k = B("k")
c = C("c")
b = D("b")
f = C("f")

j.o = f
j.x = c
k.v = j
k.y = j
k.z = b
c.o = b
c.z = b
b.w = k
b.z = k
f.o = b
f.z = b
assert b.z.y.x.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.x: C = None
        self.txt = txt

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

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

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

j = A("j")
k = B("k")
c = C("c")
b = D("b")
f = C("f")

j.o = f
j.x = c
k.v = j
k.y = j
k.z = b
c.o = b
c.z = b
b.w = k
b.z = k
f.o = b
f.z = b
assert b.z.y.x.o.w.txt == "k"