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

class B:
    def __init__(self, txt: str):
        self.s: D = None
        self.o: A = None
        self.p: D = None
        self.w: E = None
        self.txt = txt

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

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

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

m = A("m")
n = B("n")
d = C("d")
f = D("f")
c = E("c")
a = E("a")
b = C("b")
g = B("g")
h = A("h")

m.p = b
m.z = h
n.s = f
n.p = f
n.o = m
n.w = a
d.x = n
f.y = d
f.s = a
c.r = d
c.x = b
a.r = b
a.x = b
b.x = n
g.s = f
g.p = f
g.o = h
g.w = a
h.p = b
h.z = m
assert b.x.w.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.z: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: D = None
        self.o: A = None
        self.p: D = None
        self.w: E = None
        self.txt = txt

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

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

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

m = A("m")
n = B("n")
d = C("d")
f = D("f")
c = E("c")
a = E("a")
b = C("b")
g = B("g")
h = A("h")

m.p = b
m.z = h
n.s = f
n.p = f
n.o = m
n.w = a
d.x = n
f.y = d
f.s = a
c.r = d
c.x = b
a.r = b
a.x = b
b.x = n
g.s = f
g.p = f
g.o = h
g.w = a
h.p = b
h.z = m
assert b.x.w.x.x.txt == "n"