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

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

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

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

d = A("d")
i = B("i")
m = C("m")
k = D("k")
n = B("n")

d.v = n
d.u = n
i.w = m
i.x = m
m.q = d
k.u = i
n.w = m
n.x = m
assert n.w.q.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.u: B = None
        self.txt = txt

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

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

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

d = A("d")
i = B("i")
m = C("m")
k = D("k")
n = B("n")

d.v = n
d.u = n
i.w = m
i.x = m
m.q = d
k.u = i
n.w = m
n.x = m
assert n.w.q.u.x.txt == "m"