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

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

h = A("h")
c = B("c")
l = A("l")
n = B("n")
d = A("d")
b = A("b")
f = A("f")
a = B("a")
e = A("e")
m = A("m")

h.z = d
h.x = f
c.w = a
c.p = e
l.z = e
l.x = f
n.w = a
n.p = h
d.z = b
d.x = b
b.z = h
b.x = m
f.z = d
f.x = l
a.w = c
a.p = b
e.z = m
e.x = b
m.z = b
m.x = f
assert m.x.z.z.z.x.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.x: A = None
        self.txt = txt

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

h = A("h")
c = B("c")
l = A("l")
n = B("n")
d = A("d")
b = A("b")
f = A("f")
a = B("a")
e = A("e")
m = A("m")

h.z = d
h.x = f
c.w = a
c.p = e
l.z = e
l.x = f
n.w = a
n.p = h
d.z = b
d.x = b
b.z = h
b.x = m
f.z = d
f.x = l
a.w = c
a.p = b
e.z = m
e.x = b
m.z = b
m.x = f
assert m.x.z.z.z.x.z.z.z.txt == "h"