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

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

class C:
    def __init__(self, txt: str):
        self.y: D = None
        self.u: A = None
        self.txt = txt

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

d = A("d")
c = B("c")
e = C("e")
f = D("f")
n = D("n")
i = D("i")
a = B("a")
m = A("m")

d.v = c
c.w = e
c.y = m
c.q = f
e.y = i
e.u = d
f.r = d
n.r = m
i.r = m
a.w = e
a.y = m
a.q = f
m.v = c
assert m.v.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.y: D = None
        self.u: A = None
        self.txt = txt

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

d = A("d")
c = B("c")
e = C("e")
f = D("f")
n = D("n")
i = D("i")
a = B("a")
m = A("m")

d.v = c
c.w = e
c.y = m
c.q = f
e.y = i
e.u = d
f.r = d
n.r = m
i.r = m
a.w = e
a.y = m
a.q = f
m.v = c
assert m.v.w.u.txt == "d"