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

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

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

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

e = A("e")
h = B("h")
f = C("f")
b = D("b")

e.p = f
h.v = f
h.w = e
f.r = h
b.s = f
b.w = f
b.v = f
assert h.w.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

e = A("e")
h = B("h")
f = C("f")
b = D("b")

e.p = f
h.v = f
h.w = e
f.r = h
b.s = f
b.w = f
b.v = f
assert h.w.p.r.txt == "h"