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

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

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

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

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

d.u = b
d.t = a
d.x = g
g.v = c
g.p = e
c.t = m
c.w = m
c.q = e
b.r = m
a.u = e
a.t = d
a.x = g
m.t = c
m.w = c
m.q = e
e.r = m
assert m.w.t.w.q.r.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.t: A = None
        self.x: B = None
        self.txt = txt

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

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

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

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

d.u = b
d.t = a
d.x = g
g.v = c
g.p = e
c.t = m
c.w = m
c.q = e
b.r = m
a.u = e
a.t = d
a.x = g
m.t = c
m.w = c
m.q = e
e.r = m
assert m.w.t.w.q.r.w.t.txt == "m"