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

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

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

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

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

n.r = h
n.x = m
m.x = h
m.u = h
m.v = n
b.v = m
h.w = b
assert m.v.x.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.x: B = None
        self.txt = txt

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

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

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

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

n.r = h
n.x = m
m.x = h
m.u = h
m.v = n
b.v = m
h.w = b
assert m.v.x.u.w.txt == "b"