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

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

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

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

b = A("b")
f = B("f")
m = C("m")
d = D("d")
k = C("k")

b.v = m
f.o = m
f.w = k
m.u = d
m.w = k
m.x = b
d.r = b
d.o = f
k.u = d
k.w = m
k.x = b
assert m.x.v.x.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

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

b = A("b")
f = B("f")
m = C("m")
d = D("d")
k = C("k")

b.v = m
f.o = m
f.w = k
m.u = d
m.w = k
m.x = b
d.r = b
d.o = f
k.u = d
k.w = m
k.x = b
assert m.x.v.x.txt == "b"