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

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

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

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

h = A("h")
m = B("m")
i = C("i")
b = D("b")

h.v = m
m.p = i
m.w = b
i.o = b
i.v = b
b.v = m
b.p = i
b.w = i
assert i.v.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

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

h = A("h")
m = B("m")
i = C("i")
b = D("b")

h.v = m
m.p = i
m.w = b
i.o = b
i.v = b
b.v = m
b.p = i
b.w = i
assert i.v.p.o.txt == "b"