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

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

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

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

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

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

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

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

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

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

k.v = j
k.o = j
k.r = c
k.y = c
m.x = k
c.w = k
j.x = m
assert c.w.v.x.x.txt == "k"