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

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

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

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

m = A("m")
e = B("e")
g = C("g")
b = D("b")
a = D("a")
l = C("l")
d = B("d")

m.p = g
e.v = m
e.w = d
e.r = d
e.u = l
g.u = m
g.t = m
g.v = d
g.s = a
b.v = e
a.v = d
l.u = m
l.t = m
l.v = e
l.s = b
d.v = m
d.w = e
d.r = e
d.u = l
assert d.v.p.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

m = A("m")
e = B("e")
g = C("g")
b = D("b")
a = D("a")
l = C("l")
d = B("d")

m.p = g
e.v = m
e.w = d
e.r = d
e.u = l
g.u = m
g.t = m
g.v = d
g.s = a
b.v = e
a.v = d
l.u = m
l.t = m
l.v = e
l.s = b
d.v = m
d.w = e
d.r = e
d.u = l
assert d.v.p.v.v.txt == "m"