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

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

m = A("m")
n = B("n")
d = A("d")
c = A("c")
a = B("a")
g = B("g")
f = B("f")
e = B("e")

m.x = d
m.r = a
n.z = m
n.w = e
d.x = m
d.r = e
c.x = m
c.r = n
a.z = m
a.w = e
g.z = c
g.w = f
f.z = c
f.w = g
e.z = c
e.w = n
assert n.z.x.x.r.z.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.r: B = None
        self.txt = txt

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

m = A("m")
n = B("n")
d = A("d")
c = A("c")
a = B("a")
g = B("g")
f = B("f")
e = B("e")

m.x = d
m.r = a
n.z = m
n.w = e
d.x = m
d.r = e
c.x = m
c.r = n
a.z = m
a.w = e
g.z = c
g.w = f
f.z = c
f.w = g
e.z = c
e.w = n
assert n.z.x.x.r.z.r.z.txt == "m"