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

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

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

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

m = A("m")
h = B("h")
a = C("a")
f = D("f")

m.v = h
m.y = f
h.u = a
a.w = h
f.y = h
f.r = m
f.p = m
f.o = a
assert m.v.u.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.y: D = None
        self.txt = txt

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

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

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

m = A("m")
h = B("h")
a = C("a")
f = D("f")

m.v = h
m.y = f
h.u = a
a.w = h
f.y = h
f.r = m
f.p = m
f.o = a
assert m.v.u.w.u.txt == "a"