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

class B:
    def __init__(self, txt: str):
        self.t: D = None
        self.w: A = 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.x: A = None
        self.txt = txt

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

m.v = n
m.w = l
k.t = n
k.w = m
b.v = k
n.x = l
l.v = n
l.w = m
h.v = k
d.v = k
assert b.v.w.v.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.w: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: D = None
        self.w: A = 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.x: A = None
        self.txt = txt

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

m.v = n
m.w = l
k.t = n
k.w = m
b.v = k
n.x = l
l.v = n
l.w = m
h.v = k
d.v = k
assert b.v.w.v.x.v.txt == "n"