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

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

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

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

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

m.u = b
m.x = g
m.r = g
g.z = d
d.u = e
d.y = e
d.x = h
d.o = h
e.u = g
e.p = m
b.u = e
b.o = e
b.y = h
b.x = h
h.u = g
h.p = m
assert g.z.x.u.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.x: B = None
        self.r: B = None
        self.txt = txt

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

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

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

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

m.u = b
m.x = g
m.r = g
g.z = d
d.u = e
d.y = e
d.x = h
d.o = h
e.u = g
e.p = m
b.u = e
b.o = e
b.y = h
b.x = h
h.u = g
h.p = m
assert g.z.x.u.z.x.txt == "h"